|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectpractice.Collection
practice.Stack<T>
T - type of the elements stored in this stack.public class Stack<T>
This class represents a stack. A stack is a collection. The method to add elements is called push. The method to remove elements is called pop.
The element that is last added is first removed. Consider the following snippet.
StackIt produces the following output.stack = new Stack (); stack.push(2); stack.push(5); System.out.println(stack.pop()); System.out.println(stack.pop());
5 2
| Constructor Summary | |
|---|---|
Stack()
Creates an empty stack. |
|
| Method Summary | |
|---|---|
boolean |
equals(Object object)
Tests if this stack is the same as the given object. |
T |
pop()
Removes the top element of this stack. |
void |
push(T element)
Adds the given element to this stack. |
String |
toString()
Returns a string representation of this stack. |
| Methods inherited from class practice.Collection |
|---|
add, isEmpty, remove, size |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Stack()
| Method Detail |
|---|
public void push(T element)
element - the element to be added.
public T pop()
throws Exception
Exception - if this stack is empty.
public boolean equals(Object object)
equals in class Collectionobject - an object.
public String toString()
toString in class Object
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||