You can use List.of() if you don’t need a mutable list. This is the cleanest and most efficient option when you only need to read from the list.
List<String> places = List.of("Buenos Aires", "Córdoba", "La Plata");
Why?
- Immutable: This ensures no accidental modifications.
- More performant than
Arrays.asList()
(sinceList.of()
doesn’t create a fixed-size array).But: It’s immutable—no
add()
orremove()
after initialization.