Let's suppose I want to declare a List of AbstractClass
, and each of its elements must be mixed children of AbstractClass
, called SubClass1
and SubClass2
(which are not abstract, by the way). But I also want it of a specific size.
So I declare
List <AbstractClass> list = new ArrayList <AbstractClass> (SIZE);
If I add elements the to list using
list.add(new SubClass1());
list.add(new SubClass2());
are they going to be added at the end of the array or starting from index=0? In the first case, do I have to manually add elements with a loop, like this?
List <AbstractClass> list = new ArrayList <AbstractClass> (); //I've removed size
for(int i=0;i<SIZE;i++){
list.add(new SubClass1());
list.add(new SubClass2());
}