java left logo
java middle logo
java right logo
 

Home arrow Java SE Tips arrow java.util arrow How to implement a Stack
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4101
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to implement a Stack E-mail
User Rating: / 25
PoorBest 

This Java tip illustrates a method of implementing a Stack. Developer may use stack for storing elements in a memory. Stack uses First in Last out (FILO). Developer may need to use push and pop to insert and retrieve data elements from the stack.

    LinkedList stack = new LinkedList();
    
    // Push on top of stack
    stack.addFirst(object);
    
    // Pop off top of stack
    Object o = stack.getFirst();
    
    // In case multiple threads are using a stack 
    // there is a need to synchronize methods
    stack = (LinkedList)Collections.synchronizedList(stack);


 Related Tips

 
< Prev   Next >
 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.