Thursday, 18 December 2014

Java : Collection Framework : HashSet (Constructor Accepts Collection)


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

HashSetExample.java
import java.util.HashSet;
import java.util.LinkedList;

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

        /*
         * Constructs a new set containing the elements in the specified
         * collection. The HashMap is created with default load factor (0.75)
         * and an initial capacity sufficient to contain the elements in the
         * specified collection.
         */
        HashSet<Integer> hashSet = new HashSet<Integer>(linkedList);

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

    }
}

Output
linkedList : [1000, 2000]
hashSet : [1000, 2000]

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