Difference between null and empty (“”) Java String

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

    "I call it my billion-dollar mistake. It was the invention of the null reference in 1965" - https://en.wikipedia.org/wiki/Tony_Hoare

    With respect to real world both can be assumed same. Its just a syntax of a programming language that creates a difference between two as explained by others here. This simply creates overhead like when checking/comparing whether string variable has something, you have to first check if its not null and then actual string comparing ie two comparisons. This is a waste of processing power for every string comparisons.

    Objects.equals() checks for null before calling .equals().

提交回复
热议问题