THE PACKAGE JAVA.UTIL
java.util.Stack
21.12
21.12 The Class
java.util.Stack
. . . and from the stack a thin blue wreath of smoke
Curled through the air across the ripening oats . . .
 Oscar Wilde,
Charmides
 (1881)
The class
Stack
 extends
Vector
 with five operations that allow a vector to be
treated as a stack. The usual
push
 and
pop
 operations are provided, as well as a
method to
peek
 at the top item on the stack, a method to test for whether the stack
is
empty
, and a method to
search
 the stack for an item and discover how far it is
from the top.
public class Stack extends Vector {
public Object push(Object item);
public Object pop() throws EmptyStackException;
public Object peek() throws EmptyStackException;
public boolean empty();
public int search(Object o);
}
When a stack is first created, it contains no items.
21.12.1
public Object push(Object item)
The
item
 is pushed onto the top of this stack. This has exactly the same effect as:
addElement(item)
See method
addElement
 of
Vector
 ( 21.11.13).
21.12.2
public Object pop() throws EmptyStackException
If the stack is empty, an
EmptyStackException
 is thrown. Otherwise, the top 
most item (last item of the
Vector
) is removed and returned.
21.12.3
public Object peek() throws EmptyStackException
If the stack is empty, an
EmptyStackException
 is thrown. Otherwise, the top 
most item (last item of the
Vector
) is returned but not removed.
661






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved