From 651bca7c992a67edfd9c0c91be35963de380ecb6 Mon Sep 17 00:00:00 2001 From: achao Date: Tue, 28 Sep 2021 16:36:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E4=BA=86Collectors.toMap?= =?UTF-8?q?=E6=9C=AA=E6=8C=87=E5=AE=9Akey=E9=87=8D=E5=A4=8D=E7=AD=96?= =?UTF-8?q?=E7=95=A5=20=E5=AF=BC=E8=87=B4=E7=9A=84java.lang.IllegalStateEx?= =?UTF-8?q?ception:=20Duplicate=20key=20=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/hutool/core/collection/CollStreamUtil.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/collection/CollStreamUtil.java b/hutool-core/src/main/java/cn/hutool/core/collection/CollStreamUtil.java index bf1e376ea..9aef32fc0 100644 --- a/hutool-core/src/main/java/cn/hutool/core/collection/CollStreamUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/collection/CollStreamUtil.java @@ -30,7 +30,7 @@ public class CollStreamUtil { if (CollUtil.isEmpty(collection)) { return Collections.emptyMap(); } - return collection.stream().collect(Collectors.toMap(key, Function.identity())); + return collection.stream().collect(Collectors.toMap(key, Function.identity(), (l, r) -> l)); } /** @@ -49,7 +49,7 @@ public class CollStreamUtil { if (CollUtil.isEmpty(collection)) { return Collections.emptyMap(); } - return collection.stream().collect(Collectors.toMap(key, value)); + return collection.stream().collect(Collectors.toMap(key, value, (l, r) -> l)); } /** @@ -110,7 +110,7 @@ public class CollStreamUtil { } return collection .stream() - .collect(Collectors.groupingBy(key1, Collectors.toMap(key2, Function.identity()))); + .collect(Collectors.groupingBy(key1, Collectors.toMap(key2, Function.identity(), (l, r) -> l))); } /**