Stack Class

  1. It is the child interface of vector.
  2. It is specially designed class for last in first out (LIFO).

Methods in stack

  1. Object push(Object o)

For inserting an object to the stack.

  • Object pop()

To remove and return top of the object.

  • Int peak();

To return the top of the stack without removal of object.

  • Int search(Object o)

If the specified object is available it returns its offset from the top of the stack.

If the specified object is not available it returns -1.


package List;

import java.util.Stack;

public class StackDemo {
	public static void main(String[] args) {
		Stack s = new Stack();
		System.out.println(s); // [A, B, C]
		System.out.println("A")); // 3
		System.out.println("Z")); // -1


365 total views, 1 views today