I have two objects like following:
public class A {
private Integer id;
private String name;
private List list;
public A(Integer id
If you can use vanilla Java here is a very easy solution. The list is iterated at once.
Map m = new HashMap<>();
for (A a : list) {
if (m.containsKey(a.getId()))
m.get(a.getId()).getList().addAll(a.getList());
else
m.put(a.getId(), new A(a.getId(), a.getName(), a.getList()));
}
List output = new ArrayList<>(m.values());