It is very common to initialize list by array of objects in such way:
Foo[] objs = ...;
ArrayList<Foo> list = new ArrayList<Foo>(Arrays.asList(objs));
I wonder, is there any reason why desiners of ArrayList didn’t include constructor with array as parameter, so that it could be initialized like that:
ArrayList<Foo> list = new ArrayList<Foo>(objs);
May be it violates some principles, thread-safety or something else?
I don’t know why it’s not in the standard library, but Guava‘s
Listsclass hasnewArrayListwhich even helps with type inference:(You may want to import
Lists.newArrayListstatically if you use it a lot.)