How can I convert Map
to Map
?
This does not work:
Map map = ne
Now that we have Java 8/streams, we can add one more possible answer to the list:
Assuming that each of the values actually are String
objects, the cast to String
should be safe. Otherwise some other mechanism for mapping the Objects to Strings may be used.
Map map = new HashMap<>();
Map newMap = map.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> (String)e.getValue()));