Monday, 29 June 2015

Java : Collection Framework : Collections (addAll)


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

CollectionsExample.java
import java.util.ArrayList;
import java.util.Collections;

/*
 *  Example of addAll(Collection<? super T> c,
                                T... elements) method
 */

public class CollectionsExample
{

    public static void main(String[] args)
    {
        ArrayList<String> arrayList = new ArrayList<String>();

        arrayList.add("Ajay");
        arrayList.add("Vijay");
        arrayList.add("David");

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

        /*
         * Adds all of the specified elements to the specified collection.
         * Elements to be added may be specified individually or as an array
         * 
         * Returns: true if the collection changed as a result of the call
         */
        boolean isAdded = Collections.addAll(arrayList, "Raju", "Karan", "Julia");
        
        System.out.println("isAdded : "+isAdded+"\n");

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

    }

}
Output
arrayList : [Ajay, Vijay, David]

isAdded : true

arrayList : [Ajay, Vijay, David, Raju, Karan, Julia]
To Download CollectionsDemoAddAllApp Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/CollectionsDemoAddAllApp.zip?attredirects=0&d=1

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge