I have two Sets containing 2 different objects
1. Set<A>
2. Set<B>
class A {
private String id;
private String name;
private B objB;
}
class B {
private String id;
private String email;
}
I want to check if any object of A in the first Set has the same "id" in the second Set B.
If it b.getId().contains(a.getId), then that B object will be set in A object.
objA.setB(objB);
Based on a Predicate how can we store B object into A based on matching "id" attribute value (using Java streams)?
First arrange all the
idvalues from theBobjects into aMapfor fast access. Then loop theAobjects, looking up eachAobject’sidfor a match in the map.