org.apache.commons.collections
Class ArrayStack
java.lang.Object
|
+--java.util.AbstractCollection
|
+--java.util.AbstractList
|
+--java.util.ArrayList
|
+--org.apache.commons.collections.ArrayStack
- All Implemented Interfaces:
- Cloneable, Collection, List, Serializable
- public class ArrayStack
- extends ArrayList
An implementation of the Stack
API that is based on an
ArrayList
instead of a Vector
, so it is not
synchronized to protect against multi-threaded access. The implementation
is therefore operates faster in environments where you do not need to
worry about multiple thread contention.
- Version:
- $Revision: 1.4 $ $Date: 2002/02/10 08:07:42 $
- Author:
- Craig R. McClanahan
- See Also:
Stack
, Serialized Form
Method Summary |
boolean |
empty()
Return true if this stack is currently empty. |
Object |
peek()
Return the top item off of this stack without removing it. |
Object |
peek(int n)
Return the n'th item down (zero-relative) from the top of this
stack without removing it. |
Object |
pop()
Pop the top item off of this stack and return it. |
Object |
push(Object item)
Push a new item onto the top of this stack. |
int |
search(Object o)
Return the one-based position of the distance from the top that the
specified object exists on this stack, where the top-most element is
considered to be at distance 1 . |
Methods inherited from class java.util.ArrayList |
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, removeRange, set, size, toArray, toArray, trimToSize |
ArrayStack
public ArrayStack()
empty
public boolean empty()
- Return
true
if this stack is currently empty.
peek
public Object peek()
throws EmptyStackException
- Return the top item off of this stack without removing it.
- Throws:
EmptyStackExceptino
- if the stack is empty
peek
public Object peek(int n)
throws EmptyStackException
- Return the n'th item down (zero-relative) from the top of this
stack without removing it.
- Parameters:
n
- Number of items down to go- Throws:
EmptyStackException
- if there are not enough items on the
stack to satisfy this request
pop
public Object pop()
throws EmptyStackException
- Pop the top item off of this stack and return it.
- Throws:
EmptyStackException
- if the stack is empty
push
public Object push(Object item)
- Push a new item onto the top of this stack. The pushed item is also
returned.
- Parameters:
item
- Item to be added
search
public int search(Object o)
- Return the one-based position of the distance from the top that the
specified object exists on this stack, where the top-most element is
considered to be at distance
1
. If the object is not
present on the stack, return -1
instead. The
equals()
method is used to compare to the items
in this stack.
- Parameters:
o
- Object to be searched for
Copyright © 2001 Apache Software Foundation. Documenation generated April 2 2002.