Stack容器


Java 2以前は、Javaには完全な集合フレームワークがありませんでした.当時は、Vector、Stack、Hashtableなど、簡単に拡張できるコンテナクラスしかありませんでした.
JAva.util.Stack最も一般的な操作は圧入とポップアップであり、最後に圧入された要素が最初にポップアップされます.後進先出(LIFO)の原則に従います.JavaではStackの使い方も簡単で、push()が要素を押し込み、pop()で要素をポップアップします.しかし、その設計は理解できません.StackはVectorを1つの要素タイプとして機能させずにVectorを継承しています.これにより、StackもVectorを持つ行為、つまりStackをVectorとして使用することができます.これはStackの意図とは関係ありません.これはJava 1(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