我正在尝试比较2个列表,第一个列表类型为Long,第二个列表为Employee Object,我想要将结果集存储在Map<ID,Exists>
(Map<Long,Boolean>
)中。
注意:第一个列表中的第二个列表中有更多项目
List<Employee> employees = List.of(new Employee(2),new Employee(4),new Employee(6));
List<Long> ids = List.of(1L,2L,3L,4L,5L,6L);
我需要输出
1 : false
2 : true
3 : false
4 : true
5 : false
6 : true
我的代码是:
resultMap = employees.stream().collect( Collectors.toMap(Employee::getId,(
anything ->
ids.contains(anything.getId() ) )));
for (Entry<Long,Boolean> entity : resultMap.entryset()) {
System.out.println(entity.getKey() + " : " + entity.getvalue());
}
但输出是:
2 : true
4 : true
6 : true