avi*_*ldg 0 java collections guava
基本上,更好的写作方式:
Map<String, String> originalMap = getMapOfValues();
Map<String, String> newMap = originalMap.entrySet()
.stream()
.map(entry ->
Maps.immutableEntry(entry.getKey(), mapValue(entry.getValue()))
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue);
Run Code Online (Sandbox Code Playgroud)
(Maps.immutableEntry是番石榴的方法)
为什么需要将条目映射到Maps.immutableEntry()?您可以跳过该步骤:
Map<String, String> originalMap = getMapOfValues();
Map<String, String> newMap =
originalMap.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getKey,
entry -> mapValue(entry.getValue())));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
87 次 |
| 最近记录: |