xp Android
xp Android

Reputation: 109

Remove duplicate values of custom object in arraylist

How to remove duplicate values from Arraylist that have a custom object. As I have an array list of the custom object. Custom object(POJO) has many duplicate entries of latitude and longitude.

Upvotes: 1

Views: 257

Answers (1)

Ankit Dubey
Ankit Dubey

Reputation: 1170

Override hashCode() and equals() method in your POJO and use LinkedHashSet instead of ArrayList. LinkedHashSet automatically removes all duplicate objects. e.g.

java.util.LinkedHashSet<YourPojo> uniqueObjects =new java.util.LinkedHashSet<>();

Upvotes: 4

Related Questions