How do i merge two object lists in java for eg: i have 2 lists listA listB with one object each like listA[name=abc,age=56, weight=null] listB[name=Null,age=Null,weight=70]
Expected result= Output[name=abc,age=56, weight=70]
How do i merge two object lists in java for eg: i have 2 lists listA listB with one object each like listA[name=abc,age=56, weight=null] listB[name=Null,age=Null,weight=70]
Expected result= Output[name=abc,age=56, weight=70]
Copyright © 2021 Jogjafile Inc.
Sorry, read your question wrong the first time.
Here's the process you want to follow (the question is a bit unclear so I'm assuming that whether a property is null or not is an exclusive thing - for example, if A has null weight then B MUST have a non-null weight).
Loop through your lists ONCE.
Within each iteration, create a new object. Then check each property of the object in List A - if it's null, then add the corresponding property from B.
Add new object to list.
Continue iterating