Java8: HashMap <X, Y> para HashMap <X, Z> usando Stream / Map-Reduce / Collector
Eu sei como "transformar" um simples JavaList
deY
->Z
, ou seja:
List<String> x;
List<Integer> y = x.stream()
.map(s -> Integer.parseInt(s))
.collect(Collectors.toList());
Agora eu gostaria de fazer basicamente o mesmo com um mapa, ou seja:
INPUT:
{
"key1" -> "41", // "41" and "42"
"key2" -> "42 // are Strings
}
OUTPUT:
{
"key1" -> 41, // 41 and 42
"key2" -> 42 // are Integers
}
A solução não deve se limitar aString
->Integer
. Assim como noList
exemplo acima, gostaria de chamar qualquer método (ou construtor).