What is the best way to initialize an ArrayList in Java in a single line?

If you want a dynamic list initialization, you can leverage Java Streams:

ArrayList<String> places = Stream.of("Buenos Aires", "Córdoba", "La Plata")
                                 .collect(Collectors.toCollection(ArrayList::new));

:white_check_mark: Why use this?

More flexible—allows pre-processing (e.g., filtering, mapping) before collecting into a list. Still results in a modifiable ArrayList.

:rotating_light: When to use?

If you need extra processing before creating the list (e.g., converting elements, filtering duplicates).