1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
/* Append all elements of other Collection to Java ArrayList Example This Java Example shows how to append all elements of other Collection object at the end of Java ArrayList object using addAll method. This program shows how to append all elements of Java Vector to Java ArrayList object. */ import java.util.ArrayList; import java.util.Vector; public class AppendAllElementsOfOtherCollectionToArrayListExample { public static void main(String[] args) { //create an ArrayList object ArrayList arrayList = new ArrayList(); //Add elements to Arraylist arrayList.add("1"); arrayList.add("2"); arrayList.add("3"); //create a new Vector object Vector v = new Vector(); v.add("4"); v.add("5"); /* To append all elements of another Collection to ArrayList use boolean addAll(Collection c) method. It returns true if the ArrayList was changed by the method call. */ //append all elements of Vector to ArrayList arrayList.addAll(v); //display elements of ArrayList System.out.println("After appending all elements of Vector, ArrayList contains.."); for(int i=0; i<arrayList.size(); i++) System.out.println(arrayList.get(i)); } } /* Output would be After appending all elements of Vector, ArrayList contains.. 1 2 3 4 5 */ |
can u give me answer for addition of all elements in arraylist elements