How can I use a stream from two lists to get a list of unique entities? Match only by username
public class Entity {
private String username;
private String password;
}
var first = Arrays.asList(
new Entity("user1", ""),
new Entity("user2", "")
new Entity("user3", "pass3"),
new Entity("user5", "pass5")
);
var second = Arrays.asList(
new Entity("user1", "pass1"),
new Entity("user2", "pass2"),
);
public static void foo(List<Entity> first, List<Entity> second) {
List<Entity>result = Stream.of(first, second)
.flatMap(List::stream)
?
?
.collect(Collectors.toList());
}
result must be list with Entity("user3", "pass3") and Entity("user5", "pass5")