Compare two arrayLists in java

In the previous post, we have seen how to find out first and last occurrence of elements in arrayList. In this post , we will see how to compare two arrayLists in java.

We use the method named as ‘contains’ to check the existence of element present in the array list. It returns boolean value i.e. true/false. Therefore, we an use it to compare two arrayList. Let’s understand this with an example.


public boolean contains(Object o)



Total fruits: 8
Not Exist : Papaya
Exist : Mango
Not Exist : Blueberry
Exist : Grapes
Exist : Banana
Exist : Apple
Not Exist : Dates
Exist : Orange


Have any question or suggestion for us?Please feel free to post in Q&A Forum
Find out first and last occurrence of elements in ArrayList
Swap two elements in arrayList
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *