以下是字符串類'originalValue.length> size'如何在String構造函數中發生?
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;
}
的構造函數,但,我不知道怎麼會
if (originalValue.length > size)
發生的呢?評論說'修整行李',行李是指什麼?
看看這個String類的其他構造函數和方法。有沒有辦法在數組中創建一個比實際內容需要更大的分配空間的字符串? –