📄 javalang.doc12.html
字号:
<p><a name="14034"></a>
<p><font size=+1><strong>20.13.7 </strong> <code>public void <code><b>ensureCapacity</b></code>(int minimumCapacity)</code></font>
<p>
<a name="5058"></a>
If the current capacity of this <code>StringBuffer</code> object is less than the argument, then
a new internal buffer is created with greater capacity. The new capacity will be the
larger of:
<p><ul><a name="5073"></a>
<li>the <code>minimumCapacity</code> argument
<a name="5074"></a>
<li>twice the old capacity, plus <code>2</code>
</ul><a name="5081"></a>
If the <code>minimumCapacity</code> argument is nonpositive, this method takes no action and simply returns.<p>
<a name="5075"></a>
<p><font size=+1><strong>20.13.8 </strong> <code>public void <code><b>setLength</b></code>(int newLength)<br>throws IndexOutOfBoundsException</code></font>
<p>
<a name="5082"></a>
This string buffer is altered to represent a new character sequence whose length is
specified by the argument. For every nonnegative index <i>k</i> less than <code>newLength</code>,
the character at index <i>k</i> in the new character sequence is the same as the character
at index <i>k</i> in the old sequence if <i>k</i> is less than the length of the old character
sequence; otherwise, it is the null character <code>'\u0000'</code>. This method also calls the
<code>ensureCapacity</code> method <a href="javalang.doc12.html#14034">(§20.13.7)</a> with argument <code>newLength</code>.
<p><a name="5087"></a>
If the argument is negative, an <code>IndexOutOfBoundsException</code> is thrown.<p>
<a name="14036"></a>
<p><font size=+1><strong>20.13.9 </strong> <code>public char <code><b>charAt</b></code>(int index)<br>throws <code>IndexOutOfBoundsException</code></code></font>
<p>
<a name="5106"></a>
The specified character of the sequence currently represented by the string buffer,
as indicated by the <code>index</code> argument, is returned. The first character of the
sequence is at index <code>0</code>, the next at index <code>1</code>, and so on, as for array indexing.
<p><a name="5654"></a>
If the <code>index</code> argument is negative or not less than the current length <a href="javalang.doc12.html#14031">(§20.13.5)</a> of the string buffer, an <code>IndexOutOfBoundsException</code> is thrown.<p>
<a name="14038"></a>
<p><font size=+1><strong>20.13.10 </strong> <code>public void <code><b>setCharAt</b></code>(int index, char ch)<br>throws <code>IndexOutOfBoundsException</code></code></font>
<p>
<a name="5647"></a>
The string buffer is altered to represent a new character sequence that is identical
to the old character sequence, except that it contains the character <code>ch</code> at position
<code>index</code>.
<p><a name="25561"></a>
If the <code>index</code> argument is negative or not less than the current length <a href="javalang.doc12.html#14031">(§20.13.5)</a> of the string buffer, an <code>IndexOutOfBoundsException</code> is thrown.<p>
<a name="33349"></a>
<p><font size=+1><strong>20.13.11 </strong> <code>public void <code><b>getChars</b></code>(int srcBegin, int srcEnd,<br>      char[] dst, int dstBegin)<br>throws NullPointerException<code>, <br>      IndexOutOfBoundsException</code></code></font>
<p>
<a name="5668"></a>
Characters are copied from this <code>StringBuffer</code> object into the destination array
<code>dst</code>. The first character to be copied is at index <code>srcBegin</code>; the last character to be
copied is at index <code>srcEnd-1</code> (thus, the total number of characters to be copied is
<code>srcEnd-srcBegin</code>). The characters are copied into the subarray of <code>dst</code> starting at
index <code>dstBegin</code> and ending at index <code>dstbegin+(srcEnd-srcBegin)-1</code>.
<p><a name="25644"></a>
If <code>dst</code> is <code>null</code>, then a <code>NullPointerException</code> is thrown.<p>
<a name="25655"></a>
Otherwise, if any of the following is true, an <code>IndexOutOfBoundsException</code> is thrown and the destination is not modified:<p>
<ul><a name="25656"></a>
<li>The <code>srcBegin</code> argument is negative.
<a name="25657"></a>
<li>The <code>srcBegin</code> argument is greater than the <code>srcEnd</code> argument.
<a name="25659"></a>
<li><code>srcEnd</code> is greater than <code>this.length()</code>, the current length of this string buffer.
<a name="25660"></a>
<li><code>dstBegin+srcEnd-srcBegin</code> is greater than <code>dst.length</code>.
</ul><a name="14039"></a>
<p><font size=+1><strong>20.13.12 </strong> <code>public StringBuffer <code><b>append</b></code>(Object obj)</code></font>
<p>
<a name="5262"></a>
The argument is converted to a string as if by the method <code>String.valueOf</code>
<a href="javalang.doc11.html#14015">(§20.12.38)</a> and the characters of that string are then appended <a href="javalang.doc12.html#14040">(§20.13.13)</a> to this
<code>StringBuffer</code> object. A reference to this <code>StringBuffer</code> object is returned.
<p><a name="14040"></a>
<p><font size=+1><strong>20.13.13 </strong> <code>public StringBuffer <code><b>append</b></code>(String str)</code></font>
<p>
<a name="5419"></a>
The characters of the <code>String</code> argument are appended, in order, to the contents of
this string buffer, increasing the length of this string buffer by the length of the
argument. If <code>str</code> is <code>null</code>, then the four characters "<code>null</code>" are appended to this
string buffer. The method <code>ensureCapacity</code> <a href="javalang.doc12.html#14034">(§20.13.7)</a> is first called with this new
string buffer length as its argument. A reference to this <code>StringBuffer</code> object is
returned.
<p><a name="5434"></a>
Let <i>n</i> be the length of the old character sequence, the one contained in the string buffer just prior to execution of the <code>append</code> method. Then the character at index <i>k</i> in the new character sequence is equal to the character at index <i>k</i> in the old character sequence, if <i>k</i> is less than <i>n</i>; otherwise, it is equal to the character at index <i>k</i><code>-</code><i>n</i> in the argument <code>str</code>.<p>
<a name="5429"></a>
<p><font size=+1><strong>20.13.14 </strong> <code>public StringBuffer <code><b>append</b></code>(char[] str)<br>throws NullPointerException</code></font>
<p>
<a name="5354"></a>
The characters of the array argument are appended, in order, to the contents of this
string buffer, increasing the length of this string buffer by the length of the argument.
The method <code>ensureCapacity</code> <a href="javalang.doc12.html#14034">(§20.13.7)</a> is first called with this new string
buffer length as its argument. A reference to this <code>StringBuffer</code> object is
returned.
<p><a name="7094"></a>
The overall effect is exactly as if the argument were converted to a string by the method <code>String.valueOf</code> <a href="javalang.doc11.html#4778">(§20.12.39)</a> and the characters of that string were then appended <a href="javalang.doc12.html#14040">(§20.13.13)</a> to this <code>StringBuffer</code> object.<p>
<a name="14042"></a>
<p><font size=+1><strong>20.13.15 </strong> <code>public StringBuffer <code><b>append</b></code>(char[] str,<br>      int offset, int len)<br>throws NullPointerException, <br>      IndexOutOfBoundsException</code></font>
<p>
<a name="5373"></a>
Characters of the character array <code>str</code>, starting at index <code>offset</code>, are appended, in
order, to the contents of this string buffer, increasing the length of this string
buffer by <code>len</code>. The method <code>ensureCapacity</code> <a href="javalang.doc12.html#14034">(§20.13.7)</a> is first called with this
new string buffer length as its argument. A reference to this <code>StringBuffer</code> object
is returned.
<p><a name="7095"></a>
The overall effect is exactly as if the arguments were converted to a string by the method <code>String.valueOf</code> of three arguments <a href="javalang.doc11.html#33348">(§20.12.40)</a> and the characters of that string were then appended <a href="javalang.doc12.html#14040">(§20.13.13)</a> to this <code>StringBuffer</code> object.<p>
<a name="14043"></a>
<p><font size=+1><strong>20.13.16 </strong> <code>public StringBuffer <code><b>append</b></code>(boolean b)</code></font>
<p>
<a name="5275"></a>
The argument is converted to a string as if by the method <code>String.valueOf</code>
<a href="javalang.doc11.html#14020">(§20.12.41)</a> and the characters of that string are then appended <a href="javalang.doc12.html#14040">(§20.13.13)</a> to this
<code>StringBuffer</code> object. A reference to this <code>StringBuffer</code> object is returned.
<p><a name="14044"></a>
<p><font size=+1><strong>20.13.17 </strong> <code>public StringBuffer <code><b>append</b></code>(char c)</code></font>
<p>
<a name="5337"></a>
The argument is appended to the contents of this string buffer, increasing the
length of this string buffer by <code>1</code>. The method <code>ensureCapacity</code> <a href="javalang.doc12.html#14034">(§20.13.7)</a> is first
called with this new string buffer length as its argument. A reference to this
<code>StringBuffer</code> object is returned.
<p><a name="7105"></a>
The overall effect is exactly as if the argument were converted to a string by the method <code>String.valueOf</code> <a href="javalang.doc11.html#14021">(§20.12.42)</a> and the character in that string were then appended <a href="javalang.doc12.html#14040">(§20.13.13)</a> to this <code>StringBuffer</code> object.<p>
<a name="14045"></a>
<p><font size=+1><strong>20.13.18 </strong> <code>public StringBuffer <code><b>append</b></code>(int i)</code></font>
<p>
<a name="5288"></a>
The argument is converted to a string as if by the method <code>String.valueOf</code>
<a href="javalang.doc11.html#14022">(§20.12.43)</a> and the characters of that string are then appended <a href="javalang.doc12.html#14040">(§20.13.13)</a> to this
<code>StringBuffer</code> object. A reference to this <code>StringBuffer</code> object is returned.
<p><a name="14046"></a>
<p><font size=+1><strong>20.13.19 </strong> <code>public StringBuffer <code><b>append</b></code>(long l)</code></font>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -