实现
push
添加元素到末尾
public E push(E item) {
addElement(item);
return item;
}
pop、peek
直接从末尾移除元素
public synchronized E pop() {
E obj;
int len = size();
obj = peek();
removeElementAt(len - 1);
return obj;
}
public synchronized E peek() {
int len = size();
if (len == 0)
throw new EmptyStackException();
return elementAt(len - 1);
}