如果你通过这个链接这可能会清除你更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
的对象。
如果它超过最大限制会发生什么? –