问题:
java.lang.IllegalStateException:Duplicate key .....
原因:
Map中出现了重复的key记录
解决方案:
第一种写法:
Map<String, studentVO> studentMap = studentList.stream().collect(Collectors.toMap(studentVO::getId, Function.identity()));
第二种写法:
Map<String, studentVO> studentMap = studentList.stream().collect(Collectors.toMap(studentVO::getId, Function.identity(),(v1,v2)->v1));
第一种写法 没有考虑出现相同Key的情况,容易报Duplicate key......
第二种写法考虑了出现相同key的情况,采用了相关的策略(v1,v2)-> v1
想深入了解Map及策略相关内容,可自行搜索,此处不在赘述
两种写法各有利弊,根据实际业务进行取舍
本bug到此为止,下个见......