I know this question has been asked many times before. But in my problem there are two arraylist of same object type. Let us say arraylist A contains 5 elements and arraylist B contains 2 elements.
Arraylist A elements = obj1,obj2,obj3,obj4,obj5
Arraylist B elements = obj1,obj2
What I want is I want to remove all the elements of Arraylist A that exist in arraylist B i.e obj1,obj2. Then the final Arraylist A should look like:
Arraylist A = obj3,obj4,obj5
The code I implemented:
for (int i=0;i<arraylistB.size();i++){
if(arraylistA.contains(arraylistB.get(i))){
arraylistA.remove(arraylistB.get(i));
arraylistB.remove(i);
}
}
But this code deleted nothing from Arraylist A, I don't know what I'm doing wrong. Please help me!
removeAll?