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
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. 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 *