需要注意的是:
- toMap 如果集合对象有重复的key,会报错Duplicate key .... 如:Student,Student1的id都为1002。
- 可以用 (k1,k2)->k1 来设置,如果有重复的key,则保留key1,舍弃key2
Map<Integer, Student
> map= appleList.stream().collect(Collectors.toMap(Student::getId, a -> a,(k1,k2)->k1));
微信扫一扫
需要注意的是:
相关推荐