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.
-
1post your arraylist and custom POJOprimo– primo2019-05-11 05:44:11 +00:00Commented May 11, 2019 at 5:44
-
What did you try so far?danielspaniol– danielspaniol2019-05-11 06:41:36 +00:00Commented May 11, 2019 at 6:41
Add a comment
|
1 Answer
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<>();
1 Comment
xp Android
Thank you so much Ankit. Your solution is really helpful for me.