Methods Summary |
---|
public boolean | empty()Tests if this stack is empty.
return size() == 0;
|
public synchronized java.lang.Object | peek()Looks at the object at the top of this stack without removing it
from the stack.
int len = size();
if (len == 0)
throw new EmptyStackException();
return elementAt(len - 1);
|
public synchronized java.lang.Object | pop()Removes the object at the top of this stack and returns that
object as the value of this function.
Object obj;
int len = size();
obj = peek();
removeElementAt(len - 1);
return obj;
|
public java.lang.Object | push(java.lang.Object item)Pushes an item onto the top of this stack. This has exactly
the same effect as:
addElement(item)
addElement(item);
return item;
|
public synchronized int | search(java.lang.Object o)Returns the 1-based position where an object is on this stack.
If the object o occurs as an item in this stack, this
method returns the distance from the top of the stack of the
occurrence nearest the top of the stack; the topmost item on the
stack is considered to be at distance 1. The equals
method is used to compare o to the
items in this stack.
int i = lastIndexOf(o);
if (i >= 0) {
return size() - i;
}
return -1;
|