1Z10 :
I have two Maps, both sharing the same keys, .
Map<Long/*JOIN.ID*/, Long/*Temp ID*/> tempIDsMap;
Map<Long/*JOIN.ID*/, Long/*Real ID*/> realIDsMap;
What I want to get (maybe using Java 8 Stream API and avoiding loops) is the JOIN of these maps on the JOIN.ID
keys, to get a new Map like below:
Map<Long/*Temp ID*/. Long/*Real ID*/> realIDsByTempMap;
Eran :
Use Collectors.toMap
:
Map<Long,Long> realIDsByTempMap =
tempIDsMap.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getValue,
e -> realIDsMap.get(e.getKey())));