add one map to another
This commit is contained in:
parent
7773f968da
commit
1f1baf97e9
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue