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

Answer by Stefan Reich for Initialization of an ArrayList in one line

$
0
0

Why not make a simple utility function that does this?

static <A> ArrayList<A> ll(A... a) {  ArrayList l = new ArrayList(a.length);  for (A x : a) l.add(x);  return l;}

"ll" stands for "literal list".

ArrayList<String> places = ll("Buenos Aires", "Córdoba", "La Plata");

Viewing all articles
Browse latest Browse all 37

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>