I wanted to create a list of options for testing purposes. At first, I did this:
ArrayList places = new ArrayList();
places.add(\
In Java 9 we can easily initialize an ArrayList
in a single line:
List places = List.of("Buenos Aires", "Córdoba", "La Plata");
or
List places = new ArrayList<>(List.of("Buenos Aires", "Córdoba", "La Plata"));
This new approach of Java 9 has many advantages over the previous ones:
See this post for more details -> What is the difference between List.of and Arrays.asList?