Package java.util
Class Stack<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.Vector<E>
-
- java.util.Stack<E>
-
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<E>,Collection<E>,List<E>,RandomAccess
public class Stack<E> extends Vector<E>
Stackis a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables users to pop to and push from the stack, including null objects. There is no limit to the size of the stack.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description Stack()Constructs a stack with the default size ofVector.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanempty()Returns whether the stack is empty or not.Epeek()Returns the element at the top of the stack without removing it.Epop()Returns the element at the top of the stack and removes it.Epush(E object)Pushes the specified object onto the top of the stack.intsearch(Object o)Returns the index of the first occurrence of the object, starting from the top of the stack.-
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize
-
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
-
-
-
-
Method Detail
-
empty
public boolean empty()
Returns whether the stack is empty or not.- Returns:
trueif the stack is empty,falseotherwise.
-
peek
public E peek()
Returns the element at the top of the stack without removing it.- Returns:
- the element at the top of the stack.
- Throws:
EmptyStackException- if the stack is empty.- See Also:
pop()
-
pop
public E pop()
Returns the element at the top of the stack and removes it.- Returns:
- the element at the top of the stack.
- Throws:
EmptyStackException- if the stack is empty.- See Also:
peek(),push(E)
-
search
public int search(Object o)
Returns the index of the first occurrence of the object, starting from the top of the stack.- Parameters:
o- the object to be searched.- Returns:
- the index of the first occurrence of the object, assuming that the topmost object on the stack has a distance of one.
-
-