Adding all of the specified elements to the specified collection.

Elements to be added may be specified individually or as an array. The behavior of this convenience method is identical to that of c.addAll(Arrays.asList(elements)), but this method is likely to run significantly faster under most implementations.

package collection.demos;

import java.util.ArrayList;

import java.util.Collections;

public class AddingElementsToCollection{

    public static void main(String[] args) {

        ArrayList<String> list1 = new ArrayList<String>();




        System.out.println("All elements have been added : "+Collections.addAll(list1, "D","E","F"));

        System.out.println("List Items : "+list1);





All elements have been added : true

List Items : [A, B, C, D, E, F]


No comments:

Popular Posts