Posted In: Java Core, Set

How to remove duplicate objects while adding to Collection – Example1

You have list of objects (in this case users). You want to remove duplicate users depending on some criteria. You could iterate through the list ,check some condition and remove duplicates or you could use little simpler approach using HashSet and overridden equals method as below. Result [User [age=30, firstName=Super, lastName=Man], User [age=35, firstName=Bat, lastName=Man], […]

Read More

Tags: , , , ,

by , on January 25th, 2017

  • Categories