String Initializes public String() { this.offset = 0; this.count = 0; this.value = new char[0]; } public String(String original) { int size = original.count; char[] originalValue = original.value; char[] v; if (originalValue.length > size) { // The array representing the String is bigger than the new // String itself. Perhaps this constructor is being called // in order to trim the baggage, so make a copy of the array. int off = original.offset; v = Arrays.copyOfRange(originalValue, off, off+size); } else { // The array representing the String is the same // size as the String, so no point in making a copy. v = originalValue; } this.offset = 0; this.count = size; this.value = v; } String类的ValueOf方法,重点再这里 public static String valueOf(Object obj) { return (obj == null) ? "null" : obj.toString(); }
this.offset = 0;
this.count = 0;
this.value = new char[0];
}
public String(String original) {
int size = original.count;
char[] originalValue = original.value;
char[] v;
if (originalValue.length > size) {
// The array representing the String is bigger than the new
// String itself. Perhaps this constructor is being called
// in order to trim the baggage, so make a copy of the array.
int off = original.offset;
v = Arrays.copyOfRange(originalValue, off, off+size);
} else {
// The array representing the String is the same
// size as the String, so no point in making a copy.
v = originalValue;
}
this.offset = 0;
this.count = size;
this.value = v;
}
String类的ValueOf方法,重点再这里 public static String valueOf(Object obj) {
return (obj == null) ? "null" : obj.toString();
}