Friday 7 November 2014

Java : Collection Framework : LinkedList (Constructor Accepts Collection)


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

LinkedListExample.java
import java.util.HashSet;
import java.util.LinkedList;

/*
 *  Example of LinkedList(Collection<? extends E> c) Constructor.
 */
public class LinkedListExample
{

    public static void main( String[] args )
    {
        HashSet<Integer> hashSet = new HashSet<Integer>();
        hashSet.add(100);
        hashSet.add(200);
        hashSet.add(300);

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

        /*
         * Constructs a list containing the elements of the specified
         * collection, in the order they are returned by the collection's
         * iterator.
         */
        LinkedList<Integer> linkedList = new LinkedList<Integer>(hashSet);

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

    }
}

Output
hashSet : [100, 200, 300]
linkedList : [100, 200, 300]

To Download LinkedListDemoParamCons Project Click the below link

https://sites.google.com/site/javaee4321/java-collections/LinkedListDemoParamCons.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