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 to Array using toArray method
- public class JavaArrayListToArray {
- public static void main(String args[]){
- //create new ArrayList
- ArrayList<String> aListColors = new ArrayList<String>();
- aListColors.add("Red");
- aListColors.add("Green");
- aListColors.add("Blue");
- //Java ArrayList to Array using toArray method.
- /*
- * To convert Java ArrayList to Array, use
- * Object[] toArray()
- * method of ArrayList class.
- */
- Object[] colors = aListColors.toArray();
- //Java ArrayList converted to Array
- for(int i=0; i< colors.length; i++)
- System.out.println(colors[i]);
- }
- }

Post new comment