How to create an ArrayList with values in one line in Java?

1387


I want to create an ArrayList and assign some basic values into it. Is there any one liner solution available for this in Java?

1 Answer

6 years ago by

You can use the static method asList from java.util.Arrays class

List<String> colors = Arrays.asList("Red", "Green", "Blue");
6 years ago by Karthik Divi