Difference between null and empty (“”) Java String

前端 未结 22 1760
再見小時候
再見小時候 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:47

    Difference between null & empty string. For example: you have a variable named x. If you write in JS,

    var x = "";

    this means that you have assigned a value which is empty string (length is 0). Actually this is like something but which is feel of nothing :) On the other hand,

    var y = null;

    this means you've not assigned a value to y that clearly said by writing null to y at the time of declaration. If you write y.length; it will throw an error which indicates that no value assigned to y and as a result can't read length of y.

提交回复
热议问题