What's the best / most performant way to cast a List<List<T>>
to ArrayList<ArrayList<T>>
?
Let's assume I have an interface IFoo.getListOfLists()
which will give me the List<List<T>>
. Let's also assume I know that these List<List<T>>
are in fact instances of ArrayList<ArrayList<T>>
.
One simple solution would be:
ArrayList<ArrayList<T>> result = new ArrayList<>();
for (List<T> arrayList : IFoo.getListOfLists()) {
result.add((ArrayList<T>)arrayList);
}
but is there a better approach? Especially, because I already know that the instances are in fact ArrayList
s.