If obj needs to be converted to string then the result of obj.toString() and String.valueOf(obj) will be same.
But String.valueOf() is Null Safe, means it will never throw NullPointerException. 🎯
Test test = null;
// Below statement will not throw NPE
System.out.println(String.valueOf(test));
// Next statement will throw NPE
System.out.println(test.toString())
〰〰〰〰〰〰
#java #string
@ProgrammingTip