I am new to Java 8, I have 2 List of Chat, i wish to set some fields in List A from List B if their id is match
Chat:
public class Chat {
private String id;
private Status status;
private Rating rating;
//Setters and getters
}
I can do it by using nested loop, but not sure how to do it in java 8:
List<Chat> listA = getDataForA();
List<Chat> listB = getDataForB();
listA .forEach(a -> {
listB.forEach(b-> {
if (b.getId().equals(a.getId())) {
a.setRating(b.getRating());
a.setStatus(b.getStatus());
}
});
});