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;
- import java.util.Arrays;
- //Java String array to ArrayList
- public class StringArrayToArrayList {
- public static void main(String args[]){
- String[] strColors = new String[]{"Red", "Green", "Blue"};
- /*
- * To convert String Array to ArrayList use,
- * static asList(Object[] objectArray) method of
- * Arrays class.
- */
- ArrayList<String> aListColors = new ArrayList<String>(Arrays.asList(strColors));
- System.out.println("String array converted to ArrayList");
- System.out.println(aListColors);
- }
- }

Post new comment