return map.keySet().stream()
.sorted()
.collect(Collectors.joining(":"));
was throwing NullPointerExceptions.
Why?
Turns out the original map actually had a value defined for the null key, as in
"a" -> "b"
null -> "c"
So the obvious first place to look is why on earth that silly null -> "c" mapping exists.
Another option, if this is safe for your use case, is to filter with java.util.Objects::nonNull:
return map.keySet().stream()
.filter(Objects::nonNull)
.sorted()
.collect(Collectors.joining(":"));
No comments:
Post a Comment