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
Print Friendly, PDF & Email
Find out first and last occurrence of elements in ArrayList
Swap two elements in arrayList
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

Leave a Reply

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