什么是Java字符串的默认初始构造方法?
String str = "str";
相当于:
char strData[] = {'s', 't', 'r'};
String str = new String(strData);
它分配一个新的String,它表示字符的当前包含在字符数组参数(在这种情况下strData是[])的序列。从Oracle文档String类的
不,不是! 1)字符串必须被实施,并且2)字符串的构造和实习必须在课程被加载时完成*。这些使你的代码变得非常不同。 –
@StephenC请看官方的String [docs](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html)。 – ShahzadIftikhar
该文件是过分简化的东西。在某些方面它是不等同的。 –
参见构造摘要部分中[这]
Constructor and Description
String()
Initializes a newly created String object so that it represents an empty character sequence.
String(byte[] bytes)
Constructs a new String by decoding the specified array of bytes using the platform's default charset.
String(byte[] bytes, Charset charset)
Constructs a new String by decoding the specified array of bytes using the specified charset.
String(byte[] ascii, int hibyte)
Deprecated.
This method does not properly convert bytes into characters. As of JDK 1.1, the preferred way to do this is via the String constructors that take a Charset, charset name, or that use the platform's default charset.
String(byte[] bytes, int offset, int length)
Constructs a new String by decoding the specified subarray of bytes using the platform's default charset.
String(byte[] bytes, int offset, int length, Charset charset)
Constructs a new String by decoding the specified subarray of bytes using the specified charset.
String(byte[] ascii, int hibyte, int offset, int count)
Deprecated.
This method does not properly convert bytes into characters. As of JDK 1.1, the preferred way to do this is via the String constructors that take a Charset, charset name, or that use the platform's default charset.
String(byte[] bytes, int offset, int length, String charsetName)
Constructs a new String by decoding the specified subarray of bytes using the specified charset.
String(byte[] bytes, String charsetName)
Constructs a new String by decoding the specified array of bytes using the specified charset.
String(char[] value)
Allocates a new String so that it represents the sequence of characters currently contained in the character array argument.
String(char[] value, int offset, int count)
Allocates a new String that contains characters from a subarray of the character array argument.
String(int[] codePoints, int offset, int count)
Allocates a new String that contains characters from a subarray of the Unicode code point array argument.
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.
String(StringBuffer buffer)
Allocates a new string that contains the sequence of characters currently contained in the string buffer argument.
String(StringBuilder builder)
第一个答案(http://stackoverflow.com/questions/11700320/is-string -literal-pool-a-collection-of-the-string-object-or-a-col)帖子有你想知道的全部 –