The main advantage of java.util.Objects.toString() is that you can easily use it by the return value, which can be null and not need to create a new local variable (or, even worse, call the function twice).
Comparison
Foo f = getFoo(); String foo = (f==null) ? "null" : f.toString();
or worthy embellishment and error causing
String foo = (getFoo()==null) ? "null" : getFoo().toString()
to version Objects.toString based
String foo = Objects.toString(getFoo());
Michael anderson
source share