Date: 2012sep4
Update: 2025sep17
Language: Java
Q. Java: Best away to convert a Java array into an ArrayList<>
A. Use Arrays.asList() in the ArrayList constructor.
As seen in this full demo:
import java.util.ArrayList;
import java.util.Arrays;
class Demo {
public static void main(String []args) {
String [] a = { "apple", "snapple", "crackle" };
ArrayList<String> choices = new ArrayList<String>(Arrays.asList(a)); // HERE
System.out.println("choices=" + choices);
}
}
Output:
choices=[apple, snapple, crackle]