public String()
Initializes a newly created String object so that it represents an empty character sequence. Note that use of this constructor is unnecessary since Strings are immutable.
String
public 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.
Parameters:
original - A String
一般来说的话,还是直接String str = "strings";因为字符串在字符串池中是不可变的,就是字符串池中维护着字符串,当你多次使用同一个字符串的时候是直接到字符串池中来拿的,并不会占用多余的空间。用String的构造方法也可以,但是正如刚才强调的字符串池中创建了的字符串是不可变的,所以没有什么必要用new来构造。除非你需要显示的用你的字符串。 |