java left logo
java middle logo
java right logo
 

Home arrow Java SE Tips
 
 
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: 3942
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 create a Linked List E-mail
User Rating: / 91
PoorBest 

This Java tip illustrates a method of creating a List. The tip here describes various aspects of linked list such as adding an element in a list, retrieving an element and removing an element from the list.

    // Create a link list
    List list = new LinkedList()// Doubly-linked list
    list = new ArrayList();       // List implemented as growable array
    
    // Append an element to the list
    list.add("a");
    
    // Insert an element at the head (0) of the list
    list.add(0"b");
    
    // Get the number of elements in the list
    int size = list.size();          // 2
    
    // Retrieving the element at the end of the list
    Object element = list.get(list.size()-1);   // a
    
    // Retrieving the element at the head of the list
    element = list.get(0);                      // b
    
    // Deleting occurrance of the first element of the link list
    boolean b = list.remove("b");      // true
    b = list.remove("b");              // false
    
    // Remove the element at a particular index
    element = list.remove(0);          // a


 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.