Any simple way to test null before convert an object to string

The static valueOf method in the String class will do the null check and return "null" if the object is null:

String stringRepresentation = String.valueOf(o);

Leave a Comment