public class Stack<E> extends Vector<E>
Stack
is 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.capacityIncrement, elementCount, elementData
modCount
Constructor and Description |
---|
Stack()
Constructs a stack with the default size of
Vector . |
Modifier and Type | Method and Description |
---|---|
boolean |
empty()
Returns whether the stack is empty or not.
|
E |
peek()
Returns the element at the top of the stack without removing it.
|
E |
pop()
Returns the element at the top of the stack and removes it.
|
E |
push(E object)
Pushes the specified object onto the top of the stack.
|
int |
search(Object o)
Returns the index of the first occurrence of the object, starting from
the top of the stack.
|
add, add, addAll, addAll, addElement, capacity, clear, 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
iterator, listIterator, listIterator
iterator, listIterator, listIterator
public boolean empty()
true
if the stack is empty, false
otherwise.public E peek()
EmptyStackException
- if the stack is empty.pop()
public E pop()
EmptyStackException
- if the stack is empty.peek()
,
push(E)
public int search(Object o)
o
- the object to be searched.