Van icon

JAVA LINKEDLISTS

Links


    //JAVA <
    /*
    The LinkedList stores its items in "containers." The list has a link to the 
    first container and each container has a link to the next container in the list.
    To add an element to the list, the element is placed into a new container and 
    that container is linked to one of the other containers in the list.
    */
    public class A02_Linkedlists {
        
    /*
    addFirst()      Adds an item to the beginning of the list.	
    addLast()       Add an item to the end of the list	
    removeFirst()   Remove an item from the beginning of the list.	
    removeLast()    Remove an item from the end of the list	
    getFirst()      Get the item at the beginning of the list	
    getLast()       Get the item at the end of the list
    
    */
        
        /*
        When To Use
    It is best to use an ArrayList when:

    You want to access random items frequently
    You only need to add or remove elements at the end of the list
    It is best to use a LinkedList when:

    You only use the list by looping through it instead of accessing random items
    You frequently need to add and remove items from the beginning, middle or end of the
    list
        */