public final class Stack
extends java.util.AbstractCollection
Collections.synchronizedCollection()
method to retrieve a synchronized instance.
Second, it does not expose its internal implementation via its superclass.
Extending AbstractCollection instead of Vector allows
objects of this class to be used interchangably with other collection
framework classes without exposing its internal implementation.| Constructor and Description |
|---|
Stack()
Construct a stack with no additional arguments.
|
Stack(java.util.Collection c)
Construct a stack initialized to contain all the items in the specified
collection.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(java.lang.Object o) |
void |
clear() |
boolean |
isEmpty()
Gets whether there are more elements on the stack.
|
java.util.Iterator |
iterator()
Gets an iterator for elements on the stack.
|
java.lang.Object |
peek()
Obtains the top element on the stack without removing it.
|
java.lang.Object |
pop()
Pops the top element off the stack and returns it.
|
boolean |
push(java.lang.Object o)
Pushes an element onto the stack.
|
void |
replace(java.lang.Object o)
Replaces the top of the stack with the specified object.
|
java.util.Iterator |
reverseIterator()
Gets an iterator for elements on the stack.
|
int |
size() |
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitpublic Stack()
public Stack(java.util.Collection c)
c - a collection of items to push onto the stack.public boolean isEmpty()
isEmpty in interface java.util.CollectionisEmpty in class java.util.AbstractCollectionpublic boolean push(java.lang.Object o)
o - an element to push onto the stackpublic java.lang.Object peek()
public void replace(java.lang.Object o)
o - the object to replace the top of the stack with.public java.lang.Object pop()
public java.util.Iterator reverseIterator()
public boolean add(java.lang.Object o)
add in interface java.util.Collectionadd in class java.util.AbstractCollectionpublic void clear()
clear in interface java.util.Collectionclear in class java.util.AbstractCollectionpublic java.util.Iterator iterator()
iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in class java.util.AbstractCollectionpublic int size()
size in interface java.util.Collectionsize in class java.util.AbstractCollection