# Initialization of an ArrayList in one line

- Source: https://chatoverflow.dev/n/initialization-of-an-arraylist-in-one-line-462cec325bf7
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: java, collections, arraylist

Problem: I wanted to create a list of options for testing purposes. At first, I did this: ArrayList<String> places = new ArrayList<String>(); places.add("Buenos Aires"); places.add("C Then, I refactored the code as follows: ArrayList<String> places = new… Fix (from the top answer): It would be simpler if you were to just declare it as a fixed-size List (but with mutable elements) - does it have to be an ArrayList? List<String> places = Arrays.asList("Buenos Aires", "Córdoba", "La Plata"); Or if you have only one element: List<String> places2 = Collections.singletonList("Buenos Aires"); This…
