public class Stack extends ArrayList implements ViewableStack
| Constructor and Description |
|---|
Stack()
Constructs an empty Stack.
|
Stack(int initialCapacity)
Constructs an empty stack with the specified initial capacity and
with its capacity increment equal to zero.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
empty()
Tests if this stack is empty.
|
java.util.Iterator |
iterator()
Returns an iterator for this Stack.
|
java.lang.Object |
peek()
Looks at the object at the top of this stack without removing it
from the stack.
|
java.lang.Object |
peek(int n)
Peeks at n positions from the top of the stack.
|
java.lang.Object |
pop()
Removes the object at the top of this stack and returns that
object as the value of this function.
|
java.lang.Object |
push(java.lang.Object item)
Pushes an item onto the top of this stack.
|
java.lang.Object |
replace(int n,
java.lang.Object newObject)
Replaces the object at n positions from the top of the stack
with a new one; returns the old object.
|
int |
search(java.lang.Object o)
Returns the 1-based position where an object is on this stack.
|
add, add, addAll, addAll, addAll, addAll, addElement, capacity, clear, clear, clone, contains, containsAll, containsAll, copyInto, elementAt, ensureCapacity, equals, firstElement, get, hasGaps, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAll, removeAllElements, removeAllFirst, removeAllFirst, removeElement, removeElementAt, removeGaps, removeRange, retainAll, set, setElementAt, setIncrementFactor, setLast, setSize, size, toArray, toString, toStringArray, trimToSizeaddAll, containsAll, removeAll, retainAll, toArrayget, isEmpty, sizepublic Stack()
public Stack(int initialCapacity)
initialCapacity - the initial capacity of the stack.java.lang.IllegalArgumentException - if the specified initial capacity is negative.public final java.lang.Object push(java.lang.Object item)
item - the item to be pushed onto this stack.public final java.lang.Object pop()
java.lang.ArrayIndexOutOfBoundsException - if this stack is empty.public final java.lang.Object peek()
peek in interface ViewableStackjava.lang.ArrayIndexOutOfBoundsException - if this stack is empty.public final java.lang.Object peek(int n)
n - the offset from the top (0 -> top, 1 -> top-1,...)java.lang.ArrayIndexOutOfBoundsException - if index out of range.public final java.lang.Object replace(int n,
java.lang.Object newObject)
n - the offset from the top (0 -> top, 1 -> top-1,...)newObject - the new objectjava.lang.ArrayIndexOutOfBoundsException - if index out of range.public final boolean empty()
public final int search(java.lang.Object o)
o - the desired object.public java.util.Iterator iterator()
iterator in interface ViewableStackiterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in interface java.util.Listiterator in class ArrayList