【发布时间】:2019-08-30 14:05:07
【问题描述】:
我有这样的代码:
Map<Integer, Settings> operatorsSettings = new HashMap<>();
operators.forEach((operator, codeTypes) -> operatorsSettings.put(operator, mapper.convertValue(codeTypes.get(SETTINGS), Settings.class)));
return operatorsSettings;
我写了它,但我想知道。是否可以在不创建新地图的情况下编写它。像这样的东西(不正确的代码):
return operators.entrySet().stream()
.collect(entry -> Collectors.toMap(entry.getKey() , mapper.convertValue(entry.getValue().get(SETTINGS), Settings.class)));
【问题讨论】:
-
您是否尝试过使用Map.merge?
标签: java dictionary java-8 functional-programming java-stream