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