String .toString() String.valueOf(Object)区别

    String .toString()  String.valueOf(Object)区别

 

(String)

The object turn into a value of type String.

Note that the type must be able to turn into String type (such as Integer type will not work) or throw a ClassCastException

NOTE: null value can be cast to any java class type, (String) null is legal

 

.toString()

java.lang.Object class has public methods .toString (), usually derived class overrides Object in the toString () method, so any java object can call this method.

We must ensure that object is not a null value , otherwise it will throw a NullPointerException.

 

String.valueOf(Object)

Up for the lack of the first two to .toString () method is based.

Note: When using the conversion was null String.valueOf ((Object) null), instead of String.valueOf (null) (null pointer error will be reported),

The reason, we can see: https: //blog.csdn.net/a718515028/article/details/85306589

Published 247 original articles · won praise 7 · views 6598

Guess you like

Origin blog.csdn.net/weixin_41563161/article/details/104011657