You can also use the varargs syntax to make your code cleaner:
Use the overloaded constructor:
ArrayList list = new ArrayList(Arrays.asList("a", "b", "c"));
Subclass ArrayList in a utils module:
public class MyArrayList extends ArrayList {
public MyArrayList(T... values) {
super(Arrays.asList(values));
}
}
ArrayList list = new MyArrayList("a", "b", "c");
Or have a static factory method (my preferred approach):
public class Utils {
public static ArrayList asArrayList(T... values) {
return new ArrayList(Arrays.asList(values));
}
}
ArrayList list = Utils.asArrayList("a", "b", "c");