Col*_*inD 20
不要认为这里有任何想象的东西:
Map<String, Boolean> map = ...;
Map<String, Integer> newMap = Maps.newHashMapWithExpectedSize(map.size());
for (String key : map.keySet()) {
newMap.put(key, 0);
}
Run Code Online (Sandbox Code Playgroud)
如果您确实想要与番石榴一样的东西,有这个选项:
Map<String, Integer> newMap = Maps.newHashMap(
Maps.transformValues(map, Functions.constant(0)));
// 1-liner with static imports!
Map<String, Integer> newMap = newHashMap(transformValues(map, constant(0)));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
39609 次 |
| 最近记录: |