Reputation: 109
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
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