我刚刚开始研究Java 8并试用lambdas我以为我会尝试重写一个我最近编写的非常简单的东西.我需要将String of Map转换为Column到另一个String to Column的Map,其中新Map中的Column是第一个Map中Column的防御副本.列具有复制构造函数.我到目前为止最接近的是:
Map<String, Column> newColumnMap= new HashMap<>();
originalColumnMap.entrySet().stream().forEach(x -> newColumnMap.put(x.getKey(), new Column(x.getValue())));
Run Code Online (Sandbox Code Playgroud)
但我相信必须有一个更好的方法去做,我会感激一些建议.