In Java, you can't do
ArrayList<String> places = new ArrayList<String>( Arrays.asList("Buenos Aires", "Córdoba", "La Plata"));As was pointed out, you'd need to do a double brace initialization:
List<String> places = new ArrayList<String>() {{ add("x"); add("y"); }};But this may force you into adding an annotation @SuppressWarnings("serial") or generate a serial UUID which is annoying. Also most code formatters will unwrap that into multiple statements/lines.
Alternatively you can do
List<String> places = Arrays.asList(new String[] {"x", "y" });but then you may want to do a @SuppressWarnings("unchecked").
Also according to javadoc you should be able to do this:
List<String> stooges = Arrays.asList("Larry", "Moe", "Curly");But I'm not able to get it to compile with JDK 1.6.