Why is there no String.Empty in Java?

前端 未结 12 1405
悲哀的现实
悲哀的现实 2020-12-07 15:11

I understand that every time I type the string literal \"\", the same String object is referenced in the string pool.

But why doesn\'t the String API in

12条回答
  •  -上瘾入骨i
    2020-12-07 15:47

    To add on to what Noel M stated, you can look at this question, and this answer shows that the constant is reused.

    http://forums.java.net/jive/message.jspa?messageID=17122

    String constant are always "interned" so there is not really a need for such constant.

    String s=""; String t=""; boolean b=s==t; // true
    

提交回复
热议问题