Friday 24 October 2014

Java : Collection Framework : LinkedList (Add Object based on Index)


Click here to watch in Youtube : https://www.youtube.com/watch?v=kvtH4b6UO_A

LinkedListAddIndexBasedExample.java
import java.util.LinkedList;

/*
 * Example of add(int index, E element) method
 */
public class LinkedListAddIndexBasedExample
{

    public static void main( String[] args )
    {
        LinkedList<Integer> linkedList = new LinkedList<Integer>();
        linkedList.add(1);
        linkedList.add(2);
        linkedList.add(3);

        System.out.println("linkedList : " + linkedList);

        /*
         * In Position 2 adding 10
         */

        linkedList.add(2, 10);

        System.out.println("linkedList : " + linkedList);

    }

}

Output
linkedList : [1, 2, 3]
linkedList : [1, 2, 10, 3]

To Download LinkedListDemoAddIndex Project Click the below link

https://sites.google.com/site/javaee4321/java-collections/LinkedListDemoAddIndex.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment