stringbuffer.html
来自「j2se5-api-zh,java文档的中文版本」· HTML 代码 · 共 1,470 行 · 第 1/5 页
HTML
1,470 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc (build 1.5.0_03) on Wed Nov 02 09:49:56 CST 2005 --><META http-equiv="Content-Type" content="text/html; charset=gb2312"><TITLE>StringBuffer (Java 2 Platform SE 5.0)</TITLE><META NAME="keywords" CONTENT="java.lang.StringBuffer class"><LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style"><SCRIPT type="text/javascript">function windowTitle(){ parent.document.title="StringBuffer (Java 2 Platform SE 5.0)";}</SCRIPT><NOSCRIPT></NOSCRIPT></HEAD><BODY BGCOLOR="white" onload="windowTitle();"><!-- ========= START OF TOP NAVBAR ======= --><A NAME="navbar_top"><!-- --></A><A HREF="#skip-navbar_top" title="跳过导航链接"></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>概述</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>软件包</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>类</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/StringBuffer.html"><FONT CLASS="NavBarFont1"><B>使用</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>树</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>已过时</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>索引</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>帮助</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Java<sup><font size=-2>TM</font></sup> 2 Platform<br>Standard Ed. 5.0</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="String.html" title="java.lang 中的类"><B>上一个类</B></A> <A HREF="StringBuilder.html" title="java.lang 中的类"><B>下一个类</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html@java_2Flang_2FStringBuffer.html" target="_top"><B>框架</B></A> <A HREF="StringBuffer.html" target="_top"><B>无框架</B></A> <SCRIPT type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../allclasses-noframe.html"><B>所有类</B></A>'); } //--></SCRIPT><NOSCRIPT> <A HREF="../../allclasses-noframe.html"><B>所有类</B></A></NOSCRIPT></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 摘要: 嵌套 | 字段 | <A HREF="#constructor_summary">构造方法</A> | <A HREF="#method_summary">方法</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">详细信息: 字段 | <A HREF="#constructor_detail">构造方法</A> | <A HREF="#method_detail">方法</A></FONT></TD></TR></TABLE><A NAME="skip-navbar_top"></A><!-- ========= END OF TOP NAVBAR ========= --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">java.lang</FONT><BR>类 StringBuffer</H2><PRE><A HREF="Object.html" title="java.lang 中的类">java.lang.Object</A> <IMG SRC="../../resources/inherit.gif" ALT="继承者 "><B>java.lang.StringBuffer</B></PRE><DL><DT><B>所有已实现的接口:</B> <DD>java.io.Serializable, <A HREF="Appendable.html" title="java.lang 中的接口">Appendable</A>, <A HREF="CharSequence.html" title="java.lang 中的接口">CharSequence</A></DD></DL><HR><DL><DT><PRE>public final class <B>StringBuffer</B><DT>extends <A HREF="Object.html" title="java.lang 中的类">Object</A><DT>implements java.io.Serializable, <A HREF="CharSequence.html" title="java.lang 中的接口">CharSequence</A></DL></PRE><P>线程安全的可变字符序列。一个类似于 <A HREF="String.html" title="java.lang 中的类"><CODE>String</CODE></A> 的字符串缓冲区,但不能修改。虽然在任意时间点上它都包含某种特定的字符序列,但通过某些方法调用可以改变该序列的长度和内容。 <p>可将字符串缓冲区安全地用于多个线程。可以在必要时对这些方法进行同步,因此任意特定实例上的所有操作就好像是以串行顺序发生的,该顺序与所涉及的每个线程进行的方法调用顺序一致。 <p> <code>StringBuffer</code> 上的主要操作是 <code>append</code> 和 <code>insert</code> 方法,可重载这些方法,以接受任意类型的数据。每个方法都能有效地将给定的数据转换成字符串,然后将该字符串的字符追加或插入到字符串缓冲区中。<code>append</code> 方法始终将这些字符添加到缓冲区的末端;而 <code>insert</code> 方法则在指定的点添加字符。 <p>例如,如果 <code>z</code> 引用一个当前内容是“<code>start</code>”的字符串缓冲区对象,则此方法调用 <code>z.append("le")</code> 会使字符串缓冲区包含“<code>startle</code>”,而 <code>z.insert(4, "le")</code> 将更改字符串缓冲区,使之包含“<code>starlet</code>”。 <p>通常,如果 sb 引用 <code>StringBuilder</code> 的一个实例,则 <code>sb.append(x)</code> 和 <code>sb.insert(sb.length(), x)</code> 具有相同的效果。 <p>只要发生有关源序列(如在源序列中追加或插入)的操作,该类就只在执行此操作的字符串缓冲区上而不是在源上实现同步。 <p>每个字符串缓冲区都有一定的容量。只要字符串缓冲区所包含的字符序列的长度没有超出此容量,就无需分配新的内部缓冲区数组。如果内部缓冲区溢出,则此容量自动增大。从 JDK 5 开始,为该类补充了一个单个线程使用的等价类,即 <A HREF="StringBuilder.html" title="java.lang 中的类"><CODE>StringBuilder</CODE></A>。与该类相比,通常应该优先使用 <tt>StringBuilder</tt> 类,因为它支持所有相同的操作,但由于它不执行同步,所以速度更快。<P><P><DL><DT><B>从以下版本开始:</B></DT> <DD>JDK1.0</DD><DT><B>另请参见:</B><DD><A HREF="StringBuilder.html" title="java.lang 中的类"><CODE>StringBuilder</CODE></A>, <A HREF="String.html" title="java.lang 中的类"><CODE>String</CODE></A>, <A HREF="../../serialized-form.html#java.lang.StringBuffer">序列化表格</A></DL><HR><P><!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"><B>构造方法摘要</B></FONT></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="StringBuffer.html#StringBuffer()">StringBuffer</A></B>()</CODE><BR> 构造一个其中不带字符的字符串缓冲区,初始容量为 16 个字符。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="StringBuffer.html#StringBuffer(java.lang.CharSequence)">StringBuffer</A></B>(<A HREF="CharSequence.html" title="java.lang 中的接口">CharSequence</A> seq)</CODE><BR> public java.lang.StringBuilder(CharSequence seq) 构造一个字符串缓冲区,它包含与指定的 <code>CharSequence</code> 相同的字符。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="StringBuffer.html#StringBuffer(int)">StringBuffer</A></B>(int capacity)</CODE><BR> 构造一个不带字符,但具有指定初始容量的字符串缓冲区。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="StringBuffer.html#StringBuffer(java.lang.String)">StringBuffer</A></B>(<A HREF="String.html" title="java.lang 中的类">String</A> str)</CODE><BR> 构造一个字符串缓冲区,并将其内容初始化为指定的字符串内容。</TD></TR></TABLE> <!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"><B>方法摘要</B></FONT></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="StringBuffer.html" title="java.lang 中的类">StringBuffer</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#append(boolean)">append</A></B>(boolean b)</CODE><BR> Appends the string representation of the <code>boolean</code> argument to the sequence.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="StringBuffer.html" title="java.lang 中的类">StringBuffer</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#append(char)">append</A></B>(char c)</CODE><BR> Appends the string representation of the <code>char</code> argument to this sequence.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="StringBuffer.html" title="java.lang 中的类">StringBuffer</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#append(char[])">append</A></B>(char[] str)</CODE><BR> Appends the string representation of the <code>char</code> array argument to this sequence.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="StringBuffer.html" title="java.lang 中的类">StringBuffer</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#append(char[], int, int)">append</A></B>(char[] str, int offset, int len)</CODE><BR> Appends the string representation of a subarray of the <code>char</code> array argument to this sequence.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="StringBuffer.html" title="java.lang 中的类">StringBuffer</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#append(java.lang.CharSequence)">append</A></B>(<A HREF="CharSequence.html" title="java.lang 中的接口">CharSequence</A> s)</CODE><BR> 将指定的 <code>CharSequence</code> 追加到该序列。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="StringBuffer.html" title="java.lang 中的类">StringBuffer</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#append(java.lang.CharSequence, int, int)">append</A></B>(<A HREF="CharSequence.html" title="java.lang 中的接口">CharSequence</A> s, int start, int end)</CODE><BR> Appends a subsequence of the specified <code>CharSequence</code> to this sequence.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="StringBuffer.html" title="java.lang 中的类">StringBuffer</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#append(double)">append</A></B>(double d)</CODE><BR> Appends the string representation of the <code>double</code> argument to this sequence.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="StringBuffer.html" title="java.lang 中的类">StringBuffer</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#append(float)">append</A></B>(float f)</CODE><BR> Appends the string representation of the <code>float</code> argument to this sequence.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="StringBuffer.html" title="java.lang 中的类">StringBuffer</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#append(int)">append</A></B>(int i)</CODE><BR> Appends the string representation of the <code>int</code> argument to this sequence.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="StringBuffer.html" title="java.lang 中的类">StringBuffer</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#append(long)">append</A></B>(long lng)</CODE><BR> Appends the string representation of the <code>long</code> argument to this sequence.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="StringBuffer.html" title="java.lang 中的类">StringBuffer</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#append(java.lang.Object)">append</A></B>(<A HREF="Object.html" title="java.lang 中的类">Object</A> obj)</CODE><BR> Appends the string representation of the <code>Object</code> argument.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="StringBuffer.html" title="java.lang 中的类">StringBuffer</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#append(java.lang.String)">append</A></B>(<A HREF="String.html" title="java.lang 中的类">String</A> str)</CODE><BR> Appends the specified string to this character sequence.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="StringBuffer.html" title="java.lang 中的类">StringBuffer</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#append(java.lang.StringBuffer)">append</A></B>(<A HREF="StringBuffer.html" title="java.lang 中的类">StringBuffer</A> sb)</CODE><BR> 将指定的 <tt>StringBuffer</tt> 追加到此序列中。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="StringBuffer.html" title="java.lang 中的类">StringBuffer</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuffer.html#appendCodePoint(int)">appendCodePoint</A></B>(int codePoint)</CODE>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?