add one map to another

This commit is contained in:
mherbaghinyan 2018-10-02 11:42:11 +04:00
parent 7773f968da
commit 1f1baf97e9
1 changed files with 22 additions and 5 deletions

View File

@ -28,6 +28,24 @@ public class MergeMaps {
streamOf();
streamEx();
streamMerge();
}
private static void streamMerge() {
Map<String, Employee> map3 = map2.entrySet()
.stream()
.collect(
Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(v1, v2) -> new Employee(v1.getId(), v2.getName()),
() -> new HashMap<>(map1)
)
);
System.out.println(map3);
}
private static void streamEx() {
@ -75,7 +93,6 @@ public class MergeMaps {
}
private static void initialize() {
Employee employee1 = new Employee(1L, "Henry");
map1.put(employee1.getName(), employee1);