I have an Object Person(id, name).
public class Person {
/** Personid. **/
private Long personId;
/** Person Adresse. **/
private String adresse
// Getters, Setters
How can i remove duplicate person (who have same id) using CollectionUtils ? For example Person1(10, aaaa), Person2(10, bbbb), Person3(20, cccc) Result => Person1(10, aaaa), Person3(30, cccc)
EDIT :
This Solution work using Set and overrinding equals and hashcode:
List<Person> oldPerson = new ArrayList<>();
//oldPerson.add ...
Set<Person> newPerson = new HashSet<>(oldPerson);
List<Person> theRightPerson = new ArrayList<>(newPerson);
The solution that i m looking for is something like :
List<Person> theRightPerson = (List<Person>) CollectionUtils.collect(oldPerson, new Transformer() {
@Override
public Object transform(Object input) {
// TODO Auto-generated method stub
return null;
}
})