java中的字符串空构造函数 [英] String empty constructor in java
问题描述
我正在研究String API,突然间我遇到了一个String空构造函数,即我们可以使用构造一个空的String对象.string s = new String()
I was looking into the String API and suddenly I came across one String empty Constructor i.e. we can construct an empty String object using String s = new String()
我不知道有没有使用它?
I wonder is there any use of it?
推荐答案
当然.. ...
String s = new String();
将在堆上创建一个非文字String对象,将垃圾收集。
其中as
String s =;
将创建一个String Literal 。如果可以通过默认加载程序访问,那么将不会垃圾收集。
will create a String Literal. This will not be garbage collected ever, if it is reachable through the default loader.
请参阅下面的链接以查询我提出的问题。这可能与您的问题没有直接关系,但它肯定会帮助您牢牢掌握这一概念。
See this link below to a question which I asked. This may not be directly related to your question, but it will certainly help you grasp the concept firmly.
String Literal Pool是String对象或集合的引用的集合对象
这篇关于java中的字符串空构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!