0

I have two Lists of objects

PersonList1 = (
       Person(1, name),
       Person(2, name),
       Person(3, name),
       Person(4, name),
       Person(5, name),
       Person(6, name),
       Person(7, name),
       Person(8, name),
       Person(9, name),
       Person(10, name)
    );


PersonList2 = (
       Person(5, name),
       Person(7, name),
    );

Need to go through first list and if its obj Id matches with one of the ids in List2, name value must be updated from List2 into List1.

How can i do it using streams instead of loops?

ernest_k
  • 44,416
  • 5
  • 53
  • 99
vehk
  • 101
  • 7
  • Rather make a `Map` or a `Map` from `PersonList2` and loop through `PersonList1` , looking up id in PersonList2 map and updating as you go. Please try to implement it yourself first. – ernest_k May 13 '21 at 05:14
  • Mate i already tried many times, don't think creating a new topic here is the first thing i try to do:) – vehk May 13 '21 at 05:39
  • 2
    Does this answer your question? [Check if one list contains element from the other](https://stackoverflow.com/questions/11796371/check-if-one-list-contains-element-from-the-other) or https://stackoverflow.com/q/53522673/7804477 – Gautham M May 13 '21 at 06:03

0 Answers0