Basics on LinkedList
by rajesh[ Edit ] 2009-12-30 16:16:42
Basics about java LinkedList
    // Create a new link list
    List list = new LinkedList();
   Â
    // Add an element to the list
    list.add("1");
   Â
    // Insert an element at the beginning of the list
    list.add(0, "2");
   Â
    // Find the total number of elements in the list
    int size = list.size();
   Â
    // Retrieving the element at the end of the list
    Object element = list.get(list.size()-1);
   Â
    // Deleting the first occurrence of an element from the link list
    d = list.remove("2");              // returns removed element
d = list.remove("2"); // returns false as there is no such element to remove as its already deleted
    // Delte the element at a particular index
    element = list.remove(0);         Â