/**
* 移除堆栈顶部的对象,并作为此函数的值返回该对象。
*
* @return 堆栈顶部的对象( Vector 对象中的最后一项)。
* @throws EmptyStackException if this stack is empty.
*/
public synchronized E pop() {//注意此方法是 synchronized修饰的,同步方法
E obj;
int len = size();
/**
* 查看堆栈顶部的对象,但不从堆栈中移除它。
*
*/
public synchronized E peek() {
int len = size();
if (len == 0)
throw new EmptyStackException();
return elementAt(len - 1);
}
/**
* Tests if this stack is empty.
*
* 测试堆栈是否为空。 为空返回 true
*/
public boolean empty() {
return size() == 0;
}
/**
* 返回对象在堆栈中的位置,以 1 为基数。如果对象 o是堆栈中的一个项,
* 此方法返回距堆栈顶部最近的出现位置到堆栈顶部的距离;
* 堆栈中最顶部项的距离为 1。使用 equals 方法比较 o 与堆栈中的项。
*
* @param o the desired object. o - 目标对象。
* @return the 1-based position from the top of the stack where
* the object is located; the return value <code>-1</code>
* indicates that the object is not on the stack.
* 返回 : 对象到堆栈顶部的位置,以 1 为基数;返回值 -1 表示此对象不在堆栈中。
*/
public synchronized int search(Object o) {//注意此方法为 synchronized
int i = lastIndexOf(o);