如何制作一个高级流,同时匹配和比较不匹配的情况?
我有两个 Person 对象列表(List1 和 List2):
public class Person {
ObjectId id;
private List<String> names;
private Integer age;
}
我想比较列表,以及id 上有匹配项,我想检查年龄是否匹配。如果年龄确实匹配,那么我不想做任何事情,但如果年龄不匹配,那么我想返回姓名。
因此,我最终应该得到一个集合(无重复),其中包含所有对象的名称,这些对象在两个列表中都有 id,但年龄不匹配。
I have two lists (List1 and List2) of Person objects:
public class Person {
ObjectId id;
private List<String> names;
private Integer age;
}
I want to compare the Lists, and wherever there is a match on id, I want to check if the age matches. If age does match, then I don't want to do anything but if there is a mismatch in age then I want to return the names.
So I should end up with one Set (no duplicates) that contains names from all the objects that has ids in both lists but a mismatch in age.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以过滤这两个列表,将它们连接起来并平面映射到名称。像这样的东西:
You could filter both lists, concatnate them and flatmap to the names. Something like: