Use the Java 8 way of converting a Map
to Map
. This solution handles null
values.
Map keysValuesStrings = keysValues.entrySet().stream()
.filter(entry -> entry.getValue() != null)
.collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().toString()));