如果你通過這個鏈接這可能會清除你更Oracle Docs String Builder Buffer Capacity
現在想聲明任何StringBuilder類的容量,然後一個構造StringBuilder(int initCapacity)
爲這個定義。
StringBuilder(int initCapacity)
:- Creates an empty string builder with the specified initial capacity.
這裏因爲參數作爲int
一個StringBuilder
類可以是達到的最大容量將是2147483647
。
關於容量的上下文有各種方法在StringBuilder
類別中,那些方法也考慮類型int
的參數。
void setLength(int newLength) :- Sets the length of the character sequence. If newLength is less than length(), the last characters in the character sequence are truncated. If newLength is greater than length(), null characters are added at the end of the character sequence.
void ensureCapacity(int minCapacity) :- Ensures that the capacity is at least equal to the specified minimum.
這些方法也需要參數作爲int
類型。因此,使用這些方法或構造函數,您將能夠生成最大容量爲2147483647
的對象。
如果它超過最大限制會發生什麼? –