Difference between null and empty (“”) Java String

前端 未结 22 1762
再見小時候
再見小時候 2020-11-22 17:10

What is the difference between null and the \"\" (empty string)?

I have written some simple code:

String a = \"\";
String b         


        
22条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 17:39

    String s=null;

    String is not initialized for null. if any string operation tried it can throw null pointer exception

    String t="null";

    It is a string literal with value string "null" same like t = "xyz". It will not throw null pointer.

    String u="";

    It is as empty string , It will not throw null pointer.

提交回复
热议问题