View RSS Feed

Linked List

Linked List in Java

  1. Java Linked List Implementations

    by , 02-19-2012 at 07:57 AM
    Collection interface is subtype of a List. Collection interface methods are also present in list interface.
    List can’t be instantiated as it is an interface. For creation of instance of the List, create concrete implementation instance of the interface. In Java Collection APIs, these options are present:

    • java.util.ArrayList
    • java.util.LinkedList
    • java.util.Vector
    • java.util.Stack

    In java.util.concurrent package, List implementations ...
  2. What is the advantage of using an Iterator compared to the get(index) method?

    by , 02-19-2012 at 07:55 AM
    One of the following methods should be used to iterate the List.

    1. Iterator
    2. get(index)

    get(index) method is quite slower in comparison with Iterator.

    Consider this example:

    Java Code: This is the code to explain Iterator
    public class TestClass {
      public static void main(String[] args) {
        int  len = 100000;
        LinkedList linkedLst = new LinkedList(); 
        ArrayList  arrayLst = new ArrayList();
        for (int m =0; m!= len; m++)
    Linked List
  3. Removing an Item from the List

    by , 02-19-2012 at 07:52 AM
    For removal of an item out of List, different methods would be discussed here. Use these methods.

    • remove()
    • removeFirst()
    • removeLast()

    Java Code: This is the code to explain removal of an element from the List
    import java.util.*;
    public class TestLinkedList
    public static void main(String[] args)
    int pause;
    String temp;
    LinkedList theList = new LinkedList();
    Tags: remove item Add / Edit Tags
    Linked List
  4. Accessing Items from a List

    by , 02-19-2012 at 07:50 AM
    Get List Size:

    To get the List size, method “size()”is used. Size of MyList will be printed by this code.
    Java Code:
    Get Item:

    For getting a specific spot value, use get() method. In this method index of the List is provided. In case when index is not present, IndexOutOfBoundsException gets thrown.

    Element is not removed from the list by this method. Just this object is returned. This given code will ...
  5. Adding Elements to a List

    by , 02-19-2012 at 07:47 AM
    Elements are added to list by using these 4 different methods given below:
    Java Code:
    An item is added by it to end of list.
    At a particular location, elements could be added as given below.
    Java Code:
    MyList.add(0, "2");
    MyList.add(0, varName);
    Zero tells the element location, as given in above code. This is basically added as 1st element.
    Other two ...
    Linked List
  6. Java Linked Lists

    by , 02-19-2012 at 07:45 AM
    Arrays of data are stored by Linked Lists, which is considered to be a well known way of doing so. Linked List has many benefits among which a major one is that fixed size specification is not needed. To the list, you can add desired number of elements.

    Linked lists types would be discussed in this post.

    Name:  1.JPG
Views: 822
Size:  48.1 KB

    Basic Types of Linked Lists
    Tags: linked lists Add / Edit Tags
    Linked List