Java是开放源代码,如果将源代码附加到Eclipse,则始终可以使用F3来检查功能。在这种情况下,String类具有以下正在寻找的构造函数:
/**
* Allocates a new {@code String} so that it represents the sequence of
* characters currently contained in the character array argument. The
* contents of the character array are copied; subsequent modification of
* the character array does not affect the newly created string.
*
* @param value
* The initial value of the string
*/
public String(char value[]) {
int size = value.length;
this.offset = 0;
this.count = size;
this.value = Arrays.copyOf(value, size);
}
编辑:如果您想知道,Arrays.copyOf调用System.arraycopy。