You can break the filter into two stages:
this.map.entrySet().stream() .filter(entity -> entity.getValue() != null) .filter(entity -> !entity.getValue().isEmpty()) .map(obj -> String.format("%s=%s", obj.getKey(), obj.getValue())) .collect(Collectors.joining(","))
On the side of the note, most implementations of Map.Entry.toString() do exactly what you do in map() , so theoretically you could just do map(Map.Entry::toString) . But I would not rely on this if you do not create toString() or something that does not require documented or deterministic behavior.
In addition, I know that you want to abandon Guava, but here is a solution that might make you reconsider:
Joiner.on(',').withKeyValueSeparator("=") .join(Maps.filterValues(map, Predicates.not(Strings::isNullOrEmpty)));
shmosel
source share