Stack容器

在Java2之前,Java是没有完整的集合框架的。当时只有一些简单的可以自扩展的容器类,比如Vector,Stack,Hashtable等。
java.util.Stack它最常用的操作便是压入和弹出,最后压入的元素最先被弹出。它遵循后进先出(LIFO)原则。
在Java中Stack的的用法也很简单,有
push()压入一个元素,用pop()弹出一个元素。
然而它的设计却无法让人理解,Stack继承了Vector而不用Vector作为其中一个元素类型来实现其功能,
这样造成的结果是Stack也拥有Vector的行为,也就是说你可以把Stack当作一个Vector来用,而这与Stack的用意毫无关系。
这应该算为Java1(1.0/1.1)中容器类库设计者的一大失误吧
构造函数
Public Constructors
Stack()
Constructs a stack with the default size of  Vector.
主要方法
Public Methods
boolean empty()
Returns whether the stack is empty or not.
synchronized E peek()
Returns the element at the top of the stack without removing it.
synchronized E pop()
Returns the element at the top of the stack and removes it.
E push(E object)
Pushes the specified object onto the top of the stack.
synchronized int search( Object o)
Returns the index of the first occurrence of the object, starting from the top of the stack.
  注意1:因为他继承于Vector,所以它也是线程安全的,它是通过锁(自身的)来实现线程安全,其效率也很低。
  注意2:其大小也是动态增长的。
  注意3:里面的元素可以为null

你可能感兴趣的:(java,框架,vector,object,null,扩展)