I've got Google Guava inside Stream:
this.map.entrySet().stream()
.filter(entity -> !Strings.isNullOrEmpty(entity.getValue()))
.map(obj -> String.format("%s=%s", obj.getKey(), obj.getValue()))
.collect(Collectors.joining(","))
As you see there is a statement !String.isNullOrEmpty(entity) inside the filter function.
I don't want to use Guava anymore in the project, so I just want to replace it simply by:
string == null || string.length() == 0;
How can I do it more elegant?
Optional.ofNullable(string).orElse("").length() ==0Optional.ofNullable(string).orElse("").length() ==0is pure javaStringhas.isEmpty()so why bother doing the length() part at all?Strings.isNullOrEmpty()on aMap.Entry<?, ?>