The implementation of java.util.ArrayList
implements List
as well as extends AbstractList
. But in java docs you can see that AbstractL
Arrays.asList returns a List. So casting it to ArrayList is not safe as you do not know what type of List is being returned (depends on the array type it's creating the list from). Your second snippet wants an ArrayList implicitly. Hence it fails while your first snippet compiles fine because it expects a List. You can do-
ArrayList a = new ArrayList(Arrays.asList(stra));