stringbuffer.html

来自「j2se5-api-zh,java文档的中文版本」· HTML 代码 · 共 1,470 行 · 第 1/5 页

HTML
1,470
字号
</TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;void</CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#setLength(int)">setLength</A></B>(int&nbsp;newLength)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sets the length of the character sequence.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;<A HREF="CharSequence.html" title="java.lang 中的接口">CharSequence</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#subSequence(int, int)">subSequence</A></B>(int&nbsp;start,            int&nbsp;end)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns a new character sequence that is a subsequence of this sequence.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;<A HREF="String.html" title="java.lang 中的类">String</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#substring(int)">substring</A></B>(int&nbsp;start)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns a new <code>String</code> that contains a subsequence of characters currently contained in this character sequence.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;<A HREF="String.html" title="java.lang 中的类">String</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#substring(int, int)">substring</A></B>(int&nbsp;start,          int&nbsp;end)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns a new <code>String</code> that contains a subsequence of characters currently contained in this sequence.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;<A HREF="String.html" title="java.lang 中的类">String</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#toString()">toString</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns a string representing the data in this sequence.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;void</CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#trimToSize()">trimToSize</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Attempts to reduce storage used for the character sequence.</TD></TR></TABLE>&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TH ALIGN="left"><B>从类 java.lang.<A HREF="Object.html" title="java.lang 中的类">Object</A> 继承的方法</B></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="Object.html#clone()">clone</A>, <A HREF="Object.html#equals(java.lang.Object)">equals</A>, <A HREF="Object.html#finalize()">finalize</A>, <A HREF="Object.html#getClass()">getClass</A>, <A HREF="Object.html#hashCode()">hashCode</A>, <A HREF="Object.html#notify()">notify</A>, <A HREF="Object.html#notifyAll()">notifyAll</A>, <A HREF="Object.html#wait()">wait</A>, <A HREF="Object.html#wait(long)">wait</A>, <A HREF="Object.html#wait(long, int)">wait</A></CODE></TD></TR></TABLE>&nbsp;<P><!-- ========= CONSTRUCTOR DETAIL ======== --><A NAME="constructor_detail"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"><B>构造方法详细信息</B></FONT></TH></TR></TABLE><A NAME="StringBuffer()"><!-- --></A><H3>StringBuffer</H3><PRE>public <B>StringBuffer</B>()</PRE><DL><DD>构造一个其中不带字符的字符串缓冲区,初始容量为 16 个字符。<P></DL><HR><A NAME="StringBuffer(int)"><!-- --></A><H3>StringBuffer</H3><PRE>public <B>StringBuffer</B>(int&nbsp;capacity)</PRE><DL><DD>构造一个不带字符,但具有指定初始容量的字符串缓冲区。<P><DL><DT><B>参数:</B><DD><CODE>capacity</CODE> - 初始容量。<DT><B>抛出:</B><DD><CODE><A HREF="NegativeArraySizeException.html" title="java.lang 中的类">NegativeArraySizeException</A></CODE> - 如果 <code>capacity</code> 参数小于 <code>0</code>。</DL></DL><HR><A NAME="StringBuffer(java.lang.String)"><!-- --></A><H3>StringBuffer</H3><PRE>public <B>StringBuffer</B>(<A HREF="String.html" title="java.lang 中的类">String</A>&nbsp;str)</PRE><DL><DD>构造一个字符串缓冲区,并将其内容初始化为指定的字符串内容。该字符串的初始容量为 <code>16 </code> 加上字符串参数的长度。<P><DL><DT><B>参数:</B><DD><CODE>str</CODE> - 缓冲区的初始内容。<DT><B>抛出:</B><DD><CODE><A HREF="NullPointerException.html" title="java.lang 中的类">NullPointerException</A></CODE> - 如果 <code>str</code> 为 <code>null</code></DL></DL><HR><A NAME="StringBuffer(java.lang.CharSequence)"><!-- --></A><H3>StringBuffer</H3><PRE>public <B>StringBuffer</B>(<A HREF="CharSequence.html" title="java.lang 中的接口">CharSequence</A>&nbsp;seq)</PRE><DL><DD>public java.lang.StringBuilder(CharSequence seq) 构造一个字符串缓冲区,它包含与指定的 <code>CharSequence</code> 相同的字符。该字符串缓冲区的初始容量为 <code>16</code> 加上 <code>CharSequence</code> 参数的长度。 <p>如果指定的 <code>CharSequence</code> 的长度小于或等于 0,则返回容量为 <code>16</code> 的空缓冲区。<P><DL><DT><B>参数:</B><DD><CODE>seq</CODE> - 要复制的序列。<DT><B>抛出:</B><DD><CODE><A HREF="NullPointerException.html" title="java.lang 中的类">NullPointerException</A></CODE> - 如果 <code>seq</code> 为 <code>null</code><DT><B>从以下版本开始:</B></DT>  <DD>1.5</DD></DL></DL><!-- ============ METHOD DETAIL ========== --><A NAME="method_detail"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"><B>方法详细信息</B></FONT></TH></TR></TABLE><A NAME="length()"><!-- --></A><H3>length</H3><PRE>public int <B>length</B>()</PRE><DL><DD>Returns the length (character count).<P><DD><DL><DT><B>指定者:</B><DD>接口 <CODE><A HREF="CharSequence.html" title="java.lang 中的接口">CharSequence</A></CODE> 中的 <CODE><A HREF="CharSequence.html#length()">length</A></CODE></DL></DD><DD><DL><DT><B>返回:</B><DD>the length of the sequence of characters currently           represented by this object</DL></DD></DL><HR><A NAME="capacity()"><!-- --></A><H3>capacity</H3><PRE>public int <B>capacity</B>()</PRE><DL><DD>Returns the current capacity. The capacity is the amount of storage  available for newly inserted characters, beyond which an allocation  will occur.<P><DD><DL></DL></DD><DD><DL><DT><B>返回:</B><DD>the current capacity</DL></DD></DL><HR><A NAME="ensureCapacity(int)"><!-- --></A><H3>ensureCapacity</H3><PRE>public void <B>ensureCapacity</B>(int&nbsp;minimumCapacity)</PRE><DL><DD>Ensures that the capacity is at least equal to the specified minimum. If the current capacity is less than the argument, then a new internal array is allocated with greater capacity. The new capacity is the  larger of:  <ul> <li>The <code>minimumCapacity</code> argument.  <li>Twice the old capacity, plus <code>2</code>.  </ul> If the <code>minimumCapacity</code> argument is nonpositive, this method takes no action and simply returns.<P><DD><DL></DL></DD><DD><DL><DT><B>参数:</B><DD><CODE>minimumCapacity</CODE> - the minimum desired capacity.</DL></DD></DL><HR><A NAME="trimToSize()"><!-- --></A><H3>trimToSize</H3><PRE>public void <B>trimToSize</B>()</PRE><DL><DD>Attempts to reduce storage used for the character sequence. If the buffer is larger than necessary to hold its current sequence of  characters, then it may be resized to become more space efficient.  Calling this method may, but is not required to, affect the value  returned by a subsequent call to the <A HREF="StringBuffer.html#capacity()"><CODE>capacity()</CODE></A> method.<P><DD><DL></DL></DD><DD><DL><DT><B>从以下版本开始:</B></DT>  <DD>1.5</DD></DL></DD></DL><HR><A NAME="setLength(int)"><!-- --></A><H3>setLength</H3><PRE>public void <B>setLength</B>(int&nbsp;newLength)</PRE><DL><DD>Sets the length of the character sequence. The sequence is changed to 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>'&#92;u0000'</code>.    In other words, if the <code>newLength</code> argument is less than  the current length, the length is changed to the specified length. <p> If the <code>newLength</code> argument is greater than or equal  to the current length, sufficient null characters  (<code>'&#92;u0000'</code>) are appended so that  length becomes the <code>newLength</code> argument.  <p> The <code>newLength</code> argument must be greater than or equal  to <code>0</code>.<P><DD><DL></DL></DD><DD><DL><DT><B>参数:</B><DD><CODE>newLength</CODE> - the new length<DT><B>抛出:</B><DD><CODE><A HREF="IndexOutOfBoundsException.html" title="java.lang 中的类">IndexOutOfBoundsException</A></CODE> - if the               <code>newLength</code> argument is negative.<DT><B>另请参见:</B><DD><A HREF="StringBuffer.html#length()"><CODE>length()</CODE></A></DL></DD></DL><HR><A NAME="charAt(int)"><!-- --></A><H3>charAt</H3><PRE>public char <B>charAt</B>(int&nbsp;index)</PRE><DL><DD>Returns the <code>char</code> value in this sequence at the specified index. The first <code>char</code> value is at index <code>0</code>, the next at index <code>1</code>, and so on, as in array indexing. <p> The index argument must be greater than or equal to <code>0</code>, and less than the length of this sequence. <p>If the <code>char</code> value specified by the index is a <a href="Character.html#unicode">surrogate</a>, the surrogate value is returned.<P><DD><DL><DT><B>指定者:</B><DD>接口 <CODE><A HREF="CharSequence.html" title="java.lang 中的接口">CharSequence</A></CODE> 中的 <CODE><A HREF="CharSequence.html#charAt(int)">charAt</A></CODE></DL></DD><DD><DL><DT><B>参数:</B><DD><CODE>index</CODE> - the index of the desired <code>char</code> value.<DT><B>返回:</B><DD>the <code>char</code> value at the specified index.<DT><B>抛出:</B><DD><CODE><A HREF="IndexOutOfBoundsException.html" title="java.lang 中的类">IndexOutOfBoundsException</A></CODE> - if <code>index</code> is              negative or greater than or equal to <code>length()</code>.<DT><B>另请参见:</B><DD><A HREF="StringBuffer.html#length()"><CODE>length()</CODE></A></DL></DD></DL><HR><A NAME="codePointAt(int)"><!-- --></A><H3>codePointAt</H3><PRE>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?