Linked List


import java.util.Iterator;
import java.util.LinkedList;

public class LinkedListDemo 
{
    public static void main(String[] args
    {
        LinkedList list=new LinkedList();
        for (int i = 0; i < 5; i++
        {
            list.add(i);    // adds elements to the linkedlist
        }        
        Iterator i = list.iterator();   // Iterators provide a standard way to loop through all items in a collection, regardless of the type of collection
        while (i.hasNext()) 
               System.out.println(i.next())
        
        list.remove();  // removes the first element
        
        System.out.println("After deleting first element:");
        Iterator ii = list.iterator();
        while (ii.hasNext()) 
               System.out.println(ii.next());        
        
    }
}

Output:
0
1
2
3
4
After deleting first element:
1
2
3
4