"text"和new String("text")的区别

Posted RainDream

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了"text"和new String("text")的区别相关的知识,希望对你有一定的参考价值。

转自:What is the difference between “text” and new String(“text”)?

 

new String("text"); explicitly creates a new and referentially distinct instance of a Stringobject; String s = "text"; may reuse an instance from the string constant pool if one is available.

You very rarely would ever want to use the new String(anotherString) constructor.

From the API:

String(String original) : Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string. Unless an explicit copy of original is needed, use of this constructor is unnecessary since strings are immutable.

以上是关于"text"和new String("text")的区别的主要内容,如果未能解决你的问题,请参考以下文章

Parse error: parse error, unexpected $end in D:\AppServ\www\new\register.php on line

`raise "foo"` 和 `raise Exception.new("foo")` 有啥区别?

chrome浏览器 input 禁止自动填充 autocomplete="off" 无效

java.text.ParseException: Failed to parse date ["未知']

如何通过js获取当前访问页面的域名

java中String问题,String a=new String(""); 和String a=new String();有区别吗