stringbuilder.html
来自「j2se5-api-zh,java文档的中文版本」· HTML 代码 · 共 1,401 行 · 第 1/5 页
HTML
1,401 行
<!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:50:00 CST 2005 --><META http-equiv="Content-Type" content="text/html; charset=gb2312"><TITLE>StringBuilder (Java 2 Platform SE 5.0)</TITLE><META NAME="keywords" CONTENT="java.lang.StringBuilder class"><LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style"><SCRIPT type="text/javascript">function windowTitle(){ parent.document.title="StringBuilder (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/StringBuilder.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="StringBuffer.html" title="java.lang 中的类"><B>上一个类</B></A> <A HREF="StringIndexOutOfBoundsException.html" title="java.lang 中的类"><B>下一个类</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html@java_2Flang_2FStringBuilder.html" target="_top"><B>框架</B></A> <A HREF="StringBuilder.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>类 StringBuilder</H2><PRE><A HREF="Object.html" title="java.lang 中的类">java.lang.Object</A> <IMG SRC="../../resources/inherit.gif" ALT="继承者 "><B>java.lang.StringBuilder</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>StringBuilder</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>一个可变的字符序列。此类提供一个与 <code>StringBuffer</code> 兼容的 API,但不保证同步。该类被设计用作 <code>StringBuffer</code> 的一个简易替换,用在字符串缓冲区被单个线程使用的时候(这种情况很普遍)。如果可能,建议优先采用该类,因为在大多数实现中,它比 <code>StringBuffer</code> 要快。 <p>在 <code>StringBuilder</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>将 <code>StringBuilder</code> 的实例用于多个线程是不安全的。如果需要这样的同步,则建议使用 <A HREF="StringBuffer.html" title="java.lang 中的类"><CODE>StringBuffer</CODE></A>。<P><P><DL><DT><B>从以下版本开始:</B></DT> <DD>1.5</DD><DT><B>另请参见:</B><DD><A HREF="StringBuffer.html" title="java.lang 中的类"><CODE>StringBuffer</CODE></A>, <A HREF="String.html" title="java.lang 中的类"><CODE>String</CODE></A>, <A HREF="../../serialized-form.html#java.lang.StringBuilder">序列化表格</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="StringBuilder.html#StringBuilder()">StringBuilder</A></B>()</CODE><BR> 构造一个其中不带字符的字符串生成器,初始容量为 16 个字符。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="StringBuilder.html#StringBuilder(java.lang.CharSequence)">StringBuilder</A></B>(<A HREF="CharSequence.html" title="java.lang 中的接口">CharSequence</A> seq)</CODE><BR> 构造一个字符串生成器,包含与指定的 <code>CharSequence</code> 相同的字符。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="StringBuilder.html#StringBuilder(int)">StringBuilder</A></B>(int capacity)</CODE><BR> 构造一个其中不带字符的字符串生成器,初始容量由 <code>capacity</code> 参数指定。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="StringBuilder.html#StringBuilder(java.lang.String)">StringBuilder</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="StringBuilder.html" title="java.lang 中的类">StringBuilder</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuilder.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="StringBuilder.html" title="java.lang 中的类">StringBuilder</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuilder.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="StringBuilder.html" title="java.lang 中的类">StringBuilder</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuilder.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="StringBuilder.html" title="java.lang 中的类">StringBuilder</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuilder.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="StringBuilder.html" title="java.lang 中的类">StringBuilder</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuilder.html#append(java.lang.CharSequence)">append</A></B>(<A HREF="CharSequence.html" title="java.lang 中的接口">CharSequence</A> s)</CODE><BR> 向此 <tt>Appendable</tt> 追加指定的字符序列。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="StringBuilder.html" title="java.lang 中的类">StringBuilder</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuilder.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="StringBuilder.html" title="java.lang 中的类">StringBuilder</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuilder.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="StringBuilder.html" title="java.lang 中的类">StringBuilder</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuilder.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="StringBuilder.html" title="java.lang 中的类">StringBuilder</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuilder.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="StringBuilder.html" title="java.lang 中的类">StringBuilder</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuilder.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="StringBuilder.html" title="java.lang 中的类">StringBuilder</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuilder.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="StringBuilder.html" title="java.lang 中的类">StringBuilder</A></CODE></FONT></TD><TD><CODE><B><A HREF="StringBuilder.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">
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?