Reputation: 1
I have a question. Right now, I have three classes.
public C(){}
public A extends C {}
public B extends C {}
What I want to do is to create two arraylist:
ArrayList<A> list_A;
ArrayList<B> list_B;
Finally, I want to merge this two arraylists with the same father class.
I check the forum: list_A.addAll(list_B)
is used with the same class object.
Upvotes: 0
Views: 53
Reputation: 393781
You can merge them in a container of the super type :
ArrayList<C> list_C = new ArrayList<C>();
list_C.addAll(list_A);
list_C.addAll(list_B);
Upvotes: 1