我有两个不同对象的列表。
class School {
private String schoolName;
private String location;
private String pinCode;
private String rating;
}
class World {
private String schoolName;
private String location;
private String country;
private String region;
}我想从基于schoolName和location的世界对象列表中删除学校对象列表。我不能在这两个字段上使用equals和hashCode方法,因为这会产生其他问题。请帮助我如何使用流可以做到这一点。
发布于 2020-06-29 10:03:44
您可以使用filter
worldList.stream()
.filter(world -> schoolList.stream()
.anyMatch(school -> world.getSchoolName().equals(school.getSchoolName())
&& world.getLocation().equals(school.getLocation())
)
.collect(Collectors.toList());https://stackoverflow.com/questions/62635637
复制相似问题