FileDocCategorySizeDatePackage
Stack.javaAPI DocAndroid 1.5 API3595Wed May 06 22:41:04 BST 2009java.util

Stack

public class Stack extends Vector
{@code 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.
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
Constructors Summary
public Stack()
Constructs a stack with the default size of {@code Vector}.

since
Android 1.0


                       
      
        super();
    
Methods Summary
public booleanempty()
Returns whether the stack is empty or not.

return
{@code true} if the stack is empty, {@code false} otherwise.
since
Android 1.0

        return elementCount == 0;
    
public synchronized Epeek()
Returns the element at the top of the stack without removing it.

return
the element at the top of the stack.
throws
EmptyStackException if the stack is empty.
see
#pop
since
Android 1.0

        try {
            return (E)elementData[elementCount - 1];
        } catch (IndexOutOfBoundsException e) {
            throw new EmptyStackException();
        }
    
public synchronized Epop()
Returns the element at the top of the stack and removes it.

return
the element at the top of the stack.
throws
EmptyStackException if the stack is empty.
see
#peek
see
#push
since
Android 1.0

        try {
            int index = elementCount - 1;
            E obj = (E)elementData[index];
            removeElementAt(index);
            return obj;
        } catch (IndexOutOfBoundsException e) {
            throw new EmptyStackException();
        }
    
public synchronized Epush(E object)
Pushes the specified object onto the top of the stack.

param
object The object to be added on top of the stack.
return
the object argument.
see
#peek
see
#pop
since
Android 1.0

        addElement(object);
        return object;
    
public synchronized intsearch(java.lang.Object o)
Returns the index of the first occurrence of the object, starting from the top of the stack.

return
the index of the first occurrence of the object, assuming that the topmost object on the stack has a distance of one.
param
o the object to be searched.
since
Android 1.0

        int index = lastIndexOf(o);
        if (index >= 0)
            return (elementCount - index);
        return -1;