Tuesday, 23 December 2014

Java : Collection Framework : LinkedHashSet (Add group of Objects)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=9p1-Wxbtnxk&list=UUhwKlOVR041tngjerWxVccw

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

/*
 * Example of addAll(Collection<? extends E> c) method.
 */
public class LinkedHashSetExample
{
    public static void main( String[] args )
    {
        LinkedHashSet<String> linkedHashSet = new LinkedHashSet<String>();

        linkedHashSet.add("Rohan");
        linkedHashSet.add("Phil");

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

        ArrayList<String> arrayList = new ArrayList<String>();
        arrayList.add("Ram");
        arrayList.add("Dave");
        arrayList.add("Peter");

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

        /*
         * Adds all of the elements in the arrayList to the linkedHashSet.
         */

        boolean isAdded = linkedHashSet.addAll(arrayList);

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

    }
}

Output
linkedHashSet : [Rohan, Phil]

arrayList : [Ram, Dave, Peter]

isAdded : true
linkedHashSet : [Rohan, Phil, Ram, Dave, Peter]


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