Methods Summary |
---|
public boolean | empty()Returns whether the stack is empty or not.
return elementCount == 0;
|
public synchronized E | peek()Returns the element at the top of the stack without removing it.
try {
return (E)elementData[elementCount - 1];
} catch (IndexOutOfBoundsException e) {
throw new EmptyStackException();
}
|
public synchronized E | pop()Returns the element at the top of the stack and removes it.
try {
int index = elementCount - 1;
E obj = (E)elementData[index];
removeElementAt(index);
return obj;
} catch (IndexOutOfBoundsException e) {
throw new EmptyStackException();
}
|
public synchronized E | push(E object)Pushes the specified object onto the top of the stack.
addElement(object);
return object;
|
public synchronized int | search(java.lang.Object o)Returns the index of the first occurrence of the object, starting from
the top of the stack.
int index = lastIndexOf(o);
if (index >= 0)
return (elementCount - index);
return -1;
|