Find duplicate elements in ArrayList

Find duplicate elements in ArrayList –

This example will show, how to find no of duplicate item occurrence from a ArrayList.

1) No of item occurrence for a single item

2) No of occurrence of all item in the list using HashSet

3) No of occurrence of all item in the list using HashMap

4) No of occurrence of all item in the list using TreeMap

 

Output:

Count frequency for a single list item
occurence of a : 3

Count all item occurence with Set
d: 2
e: 1
b: 2
c: 3
a: 3

Count all item occurence with Map
Key : d Value : 2
Key : e Value : 1
Key : b Value : 2
Key : c Value : 3
Key : a Value : 3

Count all item occurence with Sorted Map
Key : a Value : 3
Key : b Value : 2
Key : c Value : 3
Key : d Value : 2
Key : e Value : 1

Gopal Das
Follow me

Gopal Das

Founder at GopalDas.Org
He is a technology evangelist, Salesforce trainer, blogger, and working as a Salesforce Technical Lead. After working in Java based project implementation, he jumped to the Salesforce system on a whim and never looked back. He fell in love with Salesforce’s flexibility, scalability, and power. He expanded his knowledge of the platform and became a Certified App Builder, Administrator, Platform Developer I, SalesCloud Consultant while leading the Salesforce implementation and technology needs. He has worked in a wide variety of applications/services like desktop, web and mobile applications.
Gopal Das
Follow me

Leave a Reply

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