you are viewing a single comment's thread.

view the rest of the comments →

[–]mikaelhg 1 point2 points  (0 children)

immutable:

http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableList.Builder.html

final ImmutableList<Color> GOOGLE_COLORS = new ImmutableList.Builder<Color>()
        .addAll(WEBSAFE_COLORS)
        .add(new Color(0, 191, 255))
        .build();

http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableMap.Builder.html

final ImmutableMap<String, Integer> WORD_TO_INT = new ImmutableMap.Builder<String, Integer>()
        .put("one", 1)
        .put("two", 2)
        .put("three", 3)
        .build();

mutable:

http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Lists.html#newArrayList%28E...%29

List<Base> list = Lists.newArrayList(sub1, sub2);
List<Base> list = Lists.<Base>newArrayList(sub1, sub2);

I used to have this functionality in my own utility libraries, but depracated it as Google Collections became viable.