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.

Syntax:

public boolean contains(Object o)

Example:

Output:

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


 

Questions/Suggestions
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 testingpool.com. 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 *