What is the function of the toString(Object o) and toString(Object o, String nullDefault) methods of the Objects class?

What is the function of the toString(Object o) and toString(Object o, String nullDefault) methods of the Objects class?



Answer: toString(Object o) will return the same results as the regular toString() method if the parameter is not null or returns null if the parameter is null. toString(Object o, String nullDefault) will do the same thing as the previous function, with the exception that if the value is null, it will return the second string parameter instead of null.


Learn More :

Data Structures

Learn More Multiple Choice Question :