Monday, 22 December 2014

Java : Collection Framework : LinkedHashSet (Constructor Accepts Collection)


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=l2zteIkW2zM&list=UUhwKlOVR041tngjerWxVccw

LinkedHashSetExample.java
import java.util.ArrayList;
import java.util.LinkedHashSet;

/*
 * Example of LinkedHashSet(Collection<? extends E> c) Constructor.
 */
public class LinkedHashSetExample
{
    public static void main( String[] args )
    {
        ArrayList<Integer> arrayList = new ArrayList<Integer>();
        arrayList.add(1000);
        arrayList.add(2000);
        
        System.out.println("arrayList : "+arrayList);

        /*
         * Constructs a new linked hash set with the same elements as the
         * specified collection. The linked hash set is created with an initial
         * capacity sufficient to hold the elements in the specified collection
         * and the default load factor (0.75).
         */
        LinkedHashSet<Integer> linkedHashSet = new LinkedHashSet<Integer>(
                arrayList);

        System.out.println("linkedHashSet : " + linkedHashSet + "\n");

    }
}

Output
arrayList : [1000, 2000]
linkedHashSet : [1000, 2000]

To Download LinkedHashSetDemoConsAcceptsCollection Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/LinkedHashSetDemoConsAcceptsCollection.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

    Google+ Followers

    Google+ Badge