处理了Collectors.toMap未指定key重复策略 导致的java.lang.IllegalStateException: Duplicate key 问题

This commit is contained in:
achao 2021-09-28 16:36:24 +08:00
parent bebf191c19
commit 651bca7c99

View File

@ -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)));
}
/**