Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
- import java.util.ArrayList;
- //Java ArrayList addAll
- /*
- * This Java Example shows how to add all elements of Collection to
- * Java ArrayList using addAll method.
- */
- public class JavaArrayListAddAll {
- public static void main(String args[]){
- ArrayList<String> aListBasicColors = new ArrayList<String>();
- aListBasicColors.add("Red");
- aListBasicColors.add("Green");
- aListBasicColors.add("Blue");
- ArrayList<String> aListAllColors = new ArrayList<String>();
- aListAllColors.add("White");
- aListAllColors.add("Black");
- aListAllColors.add("Cyan");
- /*
- * To add all values from any Collection to ArrayList use,
- * boolean addAll(Collection c)
- * method of Java ArrayList class.
- */
- //add all elements from one ArrayList to another
- aListAllColors.addAll(aListBasicColors);
- System.out.println("Added all elements from ArrayList" + aListAllColors);
- }
- }
- /*
- Output of above given Java ArrayList addAll example would be
- Added all elements from ArrayList[White, Black, Cyan, Red, Green, Blue]
- */

Post new comment