Difference between null and empty (“”) Java String

前端 未结 22 1701
再見小時候
再見小時候 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条回答
  •  Happy的楠姐
    2020-11-22 17:36

    null means nothing; it means you have never set a value for your variable but empty means you have set "" value to your String for instance see the following example:

    String str1;
    String str2 = "";
    

    Here str1 is null meaning that you have defined it but not set any value for it yet, but you have defined str2 and set empty value for it so it has a value even that value is "";

    but

提交回复
热议问题