Person elpidio = new Person.Builder().id(3L).firstName("elpidio").secondName("gomez").ext("121").build();
Person romual1 = new Person.Builder().id(4L).firstName("romualdo").secondName("perez").ext("141").build();
Person romual2 = new Person.Builder().id(4L).firstName("romualdo").secondName("perez").ext("144").build();
Now I need a out put some thing like this.
[Person [firstName=elpidio, secondName=gomez,ext=[121]],
Person [firstName=romualdo, secondName=perez,ext=[121,144]]]
I refereed to below ans. But the problem I found is that I have many property in Person, and out of that I just need to merge one fields. So the entry set is giving issue. Any suggestion in welcome.
Extract duplicate objects from a List in Java 8
How to merge child objects in list based on duplicate parent object
Person, inPersonclass for merged property need to be a list and how you check twoPersonobject is equal and need to merge ? Any identifier field/fields ? And also check your example may be it is wrong.keyin your case? HowfirstName="elpidio"is reassigned toid=4in the output?Personbeing the value, look up existing values when you try to add a new element and if there is one merge the two as you see fit (e.g. only add the values of theextlist/set to the list/set of the existing person).