Quantcast
Channel: Initialization of an ArrayList in one line - Stack Overflow
Viewing all articles
Browse latest Browse all 37

Answer by Akila for Initialization of an ArrayList in one line

$
0
0

Using Arrays.asList("Buenos Aires", "Córdoba", "La Plata"); is correct. but Any calls to Arrays.asList() with zero arguments or only one argument could be replaced with either a call to Collections.singletonList() or Collections.emptyList() which will save some memory.

Note: the list returned by Collections.singletonList() is immutable, while the list returned Arrays.asList() allows calling the set() method. This may break the code in rare cases.


Viewing all articles
Browse latest Browse all 37

Trending Articles