public class Stack<E> extends Vector<E>
Stack
类代表后进先出(LIFO)堆对象。它扩展了类
Vector五操作允许向量被视为一个堆栈。提供了通常的
push和
pop操作,以及一个方法
peek项目在上面的堆栈,一个为栈是否为
empty试验方法,和一个
search堆栈的项目,发现它是从顶部多远的方法。
当第一个创建堆栈时,它不包含任何项目。
一个更完整的和一致的后进先出栈操作的Deque
接口及其实现提供,应优先使用这类。例如:
Deque<Integer> stack = new ArrayDeque<Integer>();
capacityIncrement, elementCount, elementData
modCount
Constructor and Description |
---|
Stack()
创建一个空栈。
|
Modifier and Type | Method and Description |
---|---|
boolean |
empty()
测试此堆栈是否为空。
|
E |
peek()
查看此堆栈顶部的对象,而不将它从堆栈中删除。
|
E |
pop()
在这个堆栈的顶部删除对象,并返回该对象的值作为该函数的值。
|
E |
push(E item)
将一个项目推到这个堆栈的顶部。
|
int |
search(Object o)
返回元素一个对象在堆栈。
|
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, forEach, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, iterator, lastElement, lastIndexOf, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeIf, removeRange, replaceAll, retainAll, set, setElementAt, setSize, size, sort, spliterator, subList, toArray, toArray, toString, trimToSize
finalize, getClass, notify, notifyAll, wait, wait, wait
parallelStream, stream
public E push(E item)
addElement(item)
item
的项目被压入栈。
item
。
Vector.addElement(E)
public E pop()
EmptyStackException
-栈是否为空。
public E peek()
EmptyStackException
-栈是否为空。
public boolean empty()
true
当且仅当这堆不包含项目;
false
否则。
public int search(Object o)
o
-理想对象。
-1
表明对象的堆栈。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.