С помощью Eclipse Collections вы можете написать следующее:
List<String> list = Lists.mutable.with("s1", "s2", "s3");
Вы также можете более точно указать типы и их изменчивость или неизменность.
MutableList<String> mList = Lists.mutable.with("s1", "s2", "s3");
ImmutableList<String> iList = Lists.immutable.with("s1", "s2", "s3");
Вы также можете сделать то же самое с наборами, сумками и картами:
Set<String> set = Sets.mutable.with("s1", "s2", "s3");
MutableSet<String> mSet = Sets.mutable.with("s1", "s2", "s3");
ImmutableSet<String> iSet = Sets.immutable.with("s1", "s2", "s3");
Bag<String> bag = Bags.mutable.with("s1", "s2", "s3");
MutableBag<String> mBag = Bags.mutable.with("s1", "s2", "s3");
ImmutableBag<String> iBag = Bags.immutable.with("s1", "s2", "s3");
Map<String, String> map =
Maps.mutable.with("s1", "s1", "s2", "s2", "s3", "s3");
MutableMap<String, String> mMap =
Maps.mutable.with("s1", "s1", "s2", "s2", "s3", "s3");
ImmutableMap<String, String> iMap =
Maps.immutable.with("s1", "s1", "s2", "s2", "s3", "s3");
Есть также фабрики для SortedSets, SortedBags и SortedMaps.
SortedSet<String> sortedSet = SortedSets.mutable.with("s1", "s2", "s3");
MutableSortedSet<String> mSortedSet = SortedSets.mutable.with("s1", "s2", "s3");
ImmutableSortedSet<String> iSortedSet = SortedSets.immutable.with("s1", "s2", "s3");
SortedBag<String> sortedBag = SortedBags.mutable.with("s1", "s2", "s3");
MutableSortedBag<String> mSortedBag = SortedBags.mutable.with("s1", "s2", "s3");
ImmutableSortedBag<String> iSortedBag = SortedBags.immutable.with("s1", "s2", "s3");
SortedMap<String, String> sortedMap =
SortedMaps.mutable.with("s1", "s1", "s2", "s2", "s3","s3");
MutableSortedMap<String, String> mSortedMap =
SortedMaps.mutable.with("s1", "s1", "s2", "s2", "s3","s3");
ImmutableSortedMap<String, String> iSortedMap =
SortedMaps.immutable.with("s1", "s1", "s2", "s2", "s3","s3");
Примечание: Я коммиттер Eclipse Collections.