ArrayList<String> places = new ArrayList<String>();
places.add("Buenos Aires");
places.add("Córdoba");
places.add("La Plata");
Then I refactored the code as follows:
ArrayList<String> places = new ArrayList<String>(
Arrays.asList("Buenos Aires", "Córdoba", "La Plata"));
Is there a better way to do this?
Anonymous User
12-May-2015ArrayList<String> list = new ArrayList<String>() {{add("A");
add("B");
add("C");
}};
List<String> places = Arrays.asList("Buenos Aires", "Córdoba", "La Plata");ArrayList<String> places = new ArrayList<>(Arrays.asList("Buenos Aires", "Córdoba", "La Plata"))