Quantcast
Viewing latest article 18
Browse Latest Browse All 37

Answer by Donald Raab for Initialization of an ArrayList in one line

With Eclipse Collections you can write the following:

List<String> list = Lists.mutable.with("Buenos Aires", "Córdoba", "La Plata");

You can also be more specific about the types and whether they are Mutable or Immutable.

MutableList<String> mList = Lists.mutable.with("Buenos Aires", "Córdoba", "La Plata");ImmutableList<String> iList = Lists.immutable.with("Buenos Aires", "Córdoba", "La Plata");

You can also do the same with Sets and Bags:

Set<String> set = Sets.mutable.with("Buenos Aires", "Córdoba", "La Plata");MutableSet<String> mSet = Sets.mutable.with("Buenos Aires", "Córdoba", "La Plata");ImmutableSet<String> iSet = Sets.immutable.with("Buenos Aires", "Córdoba", "La Plata");Bag<String> bag = Bags.mutable.with("Buenos Aires", "Córdoba", "La Plata");MutableBag<String> mBag = Bags.mutable.with("Buenos Aires", "Córdoba", "La Plata");ImmutableBag<String> iBag = Bags.immutable.with("Buenos Aires", "Córdoba", "La Plata");

Note: I am a committer for Eclipse Collections.


Viewing latest article 18
Browse Latest Browse All 37

Trending Articles



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