1
0
mirror of https://github.com/Snailclimb/JavaGuide synced 2025-06-16 18:10:13 +08:00

集合转Map抛出异常的常见情形提醒

This commit is contained in:
Wenweigood 2025-05-13 19:57:42 +08:00 committed by GitHub
parent 6f3f2c90fe
commit 7980d03265
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -134,6 +134,7 @@ public static <T> T requireNonNull(T obj) {
return obj; return obj;
} }
``` ```
> `Collectors`也提供了无需mergeFunction的`toMap()`方法但此时若出现key冲突则会抛出`duplicateKeyException`异常,因此强烈建议使用`toMap()`方法必填mergeFunction。
## 集合遍历 ## 集合遍历