- 类定义
//该类继承了Vector类(具有线程安全性,因为Vetor的增删查改方法都被线程同步了。)
public Statck<E> extends Vector<E>
- 构造方法
//构造方法
public Stack(){
}
- 栈的基本操作
//将元素压栈,并返回该元素
public E push(E item){
addElement(item)
return item;
}
//元素出栈,并返回该元素
public synchronized E pop(){
E obj;
int len = size();
obj=peek();
removeElementAt(len-1);
return obj;
}
//返回栈顶元素
public sysnchronized E peek(){
int len = size();
if(len = 0)
throw new EmptyStackException();
return elementAt(len -1);
}
//判断栈是否为空
public boolean empty(){
return size()==0;
}