4 ms·
If you use the Google library [1], this becomes a bit more convenient that the built-in Java way: List<String> people = ImmutableList.of("Frank", "Mary", "B
by rtg 15y ago
If you use the Google library [1], this becomes a bit more convenient that the built-in Java way:
List<String> people = ImmutableList.of("Frank", "Mary", "Bob");
There's also ImmutableSet and many other goodies, to say the least. For instantiation of these generic types, you can do:
List<String> people = Lists.newArrayList();
Map<String,Integer> scores = Maps.newHashMap();
and so on.
[1] http://code.google.com/p/guava-libraries/ http://code.google.com/p/guava-libraries/
- markelliot 15y agoSince 1.5 you can use the `Arrays` built-in [1]: List<String> people = Arrays.asList("Frank", "Mary", "Bob"); [1] http://download.oracle.com/javase/1.5.0/docs/api/java/util/Arrays.html http://download.oracle.com/javase/1.5.0/docs/api/java/util/A...