Collectors.toMap报错java.lang.IllegalStateException: Duplicate key
参考:Collectors.toMap出现重复key问题
Java8 Stream流Collectors.toMap当key重复时报异常(IllegalStateException)
toMap(Function, Function) 返回一个 Collector,它将元素累积到一个 Map中,其键和值是将提供的映射函数应用于输入元素的结果。
如果映射的键包含重复项,则在执行收集操作时会抛出IllegalStateException。如果映射的键可能有重复项,请改用 toMap(Function, Function, BinaryOperator),如下:
Collectors.toMap(User::getNo,
User::getName,
(existing, replacement) -> existing
)