Java in comparison with the empty string to null String

String obj = null;

Assigned to the null object obj obj is not specifically directed,

Comparison of Methods: obj == null, will return true

isEmpty,equals,length均为NullPointerException

String obj2 = "";

Empty string assigned to obj2

Comparison of Methods: obj2 == "", returns true,

Or obj2.isEmpty (), returns true

Or obj2.equals (null), returns true

Or obj2.length () == 0, returns true

Note obj2 == null, returns false

Published 37 original articles · won praise 29 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_42755868/article/details/84579288