1

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.

2
  • 1
    post your arraylist and custom POJO Commented May 11, 2019 at 5:44
  • What did you try so far? Commented May 11, 2019 at 6:41

1 Answer 1

4

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<>();
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much Ankit. Your solution is really helpful for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.