string.html
来自「j2se5-api-zh,java文档的中文版本」· HTML 代码 · 共 1,218 行 · 第 1/5 页
HTML
1,218 行
<!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:53 CST 2005 --><META http-equiv="Content-Type" content="text/html; charset=gb2312"><TITLE>String (Java 2 Platform SE 5.0)</TITLE><META NAME="keywords" CONTENT="java.lang.String class"><LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style"><SCRIPT type="text/javascript">function windowTitle(){ parent.document.title="String (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/String.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="StrictMath.html" title="java.lang 中的类"><B>上一个类</B></A> <A HREF="StringBuffer.html" title="java.lang 中的类"><B>下一个类</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html@java_2Flang_2FString.html" target="_top"><B>框架</B></A> <A HREF="String.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="#field_summary">字段</A> | <A HREF="#constructor_summary">构造方法</A> | <A HREF="#method_summary">方法</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">详细信息: <A HREF="#field_detail">字段</A> | <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>类 String</H2><PRE><A HREF="Object.html" title="java.lang 中的类">java.lang.Object</A> <IMG SRC="../../resources/inherit.gif" ALT="继承者 "><B>java.lang.String</B></PRE><DL><DT><B>所有已实现的接口:</B> <DD>java.io.Serializable, <A HREF="CharSequence.html" title="java.lang 中的接口">CharSequence</A>, <A HREF="Comparable.html" title="java.lang 中的接口">Comparable</A><<A HREF="String.html" title="java.lang 中的类">String</A>></DD></DL><HR><DL><DT><PRE>public final class <B>String</B><DT>extends <A HREF="Object.html" title="java.lang 中的类">Object</A><DT>implements java.io.Serializable, <A HREF="Comparable.html" title="java.lang 中的接口">Comparable</A><<A HREF="String.html" title="java.lang 中的类">String</A>>, <A HREF="CharSequence.html" title="java.lang 中的接口">CharSequence</A></DL></PRE><P><code>String</code> 类代表字符串。Java 程序中的所有字符串字面值(如 <code>"abc"</code> )都作为此类的实例来实现。 <p>字符串是常量;它们的值在创建之后不能改变。字符串缓冲区支持可变的字符串。因为 String 对象是不可变的,所以可以共享它们。例如: <p><blockquote><pre> String str = "abc"; </pre></blockquote><p>等效于: <p><blockquote><pre> char data[] = {'a', 'b', 'c'}; String str = new String(data); </pre></blockquote><p>下面给出了一些如何使用字符串的更多例子: <p><blockquote><pre> System.out.println("abc"); String cde = "cde"; System.out.println("abc" + cde); String c = "abc".substring(2,3); String d = cde.substring(1, 2); </pre></blockquote> <p><code>String</code> 类包括的方法有:检查序列的单个字符;比较字符串;搜索字符串;提取子字符串;创建字符串副本,在该副本中,所有的字符都被转换为大写或小写形式。大小写映射基于 <A HREF="Character.html" title="java.lang 中的类"><CODE>Character</CODE></A> 类指定的 Unicode Standard 版本。 <p>Java 语言提供对字符串串联符号("+")和其他对象到字符串的转换的特殊支持。字符串串联是通过 <code>StringBuilder</code>(或 <code>StringBuffer</code>)类及其 <code>append</code> 方法实现的。字符串转换是通过 <code>toString</code> 方法实现的,该方法由 <code>Object</code> 类定义,并可被 Java 中所有类继承。有关字符串串联和转换的更多信息,请参阅 Gosling、Joy 和 Steele 合著的《<i>The Java Language Specification</i>》。<p> 除非另行说明,否则将 <tt>null</tt> 参数传递给此类中的构造方法或方法都会抛出 <A HREF="NullPointerException.html" title="java.lang 中的类"><CODE>NullPointerException</CODE></A>。<p><code>String</code> 表示一个 UTF-16 格式的字符串,其中的<em>增补字符</em> 由<em>代理项对</em> 表示(有关详细信息,请参阅 <code>Character</code> 类中的 <a href="Character.html#unicode">Unicode 字符表示形式</a>)。索引值是指 <code>char</code> 代码单元,因此增补字符在 <code>String</code> 中占用两个位置。<p><code>String</code> 类提供处理 Unicode 代码点(即字符)和 Unicode 代码单元(即 <code>char</code> 值)的方法。<P><P><DL><DT><B>从以下版本开始:</B></DT> <DD>JDK1.0</DD><DT><B>另请参见:</B><DD><A HREF="Object.html#toString()"><CODE>Object.toString()</CODE></A>, <A HREF="StringBuffer.html" title="java.lang 中的类"><CODE>StringBuffer</CODE></A>, <A HREF="StringBuilder.html" title="java.lang 中的类"><CODE>StringBuilder</CODE></A>, <CODE>Charset</CODE>, <A HREF="../../serialized-form.html#java.lang.String">序列化表格</A></DL><HR><P><!-- =========== FIELD SUMMARY =========== --><A NAME="field_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>static <A HREF="../util/Comparator.html" title="java.util 中的接口">Comparator</A><<A HREF="String.html" title="java.lang 中的类">String</A>></CODE></FONT></TD><TD><CODE><B><A HREF="String.html#CASE_INSENSITIVE_ORDER">CASE_INSENSITIVE_ORDER</A></B></CODE><BR> 一个排序 <code>String</code> 对象的 Comparator,它的作用与 <code>compareToIgnoreCase</code> 相同。</TD></TR></TABLE> <!-- ======== 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="String.html#String()">String</A></B>()</CODE><BR> 初始化一个新创建的 <code>String</code> 对象,它表示一个空字符序列。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="String.html#String(byte[])">String</A></B>(byte[] bytes)</CODE><BR> 构造一个新的 <tt>String</tt>,方法是使用平台的默认字符集解码字节的指定数组。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="String.html#String(byte[], int)">String</A></B>(byte[] ascii, int hibyte)</CODE><BR> <B>已过时。</B> <I>该方法无法将字节正确转换为字符。从 JDK 1.1 起,完成该转换的首选方法是通过 <code>String</code> 构造方法,该方法接受一个字符集名称或使用平台的默认字符集。</I></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="String.html#String(byte[], int, int)">String</A></B>(byte[] bytes, int offset, int length)</CODE><BR> 构造一个新的 <tt>String</tt>,方法是使用指定的字符集解码字节的指定子数组。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="String.html#String(byte[], int, int, int)">String</A></B>(byte[] ascii, int hibyte, int offset, int count)</CODE><BR> <B>已过时。</B> <I>该方法无法将字节正确转换为字符。从 JDK 1.1 开始,完成该转换的首选方法是通过 <code>String</code> 构造方法,它接受一个字符集名称,或者使用平台默认的字符集。</I></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="String.html#String(byte[], int, int, java.lang.String)">String</A></B>(byte[] bytes, int offset, int length, <A HREF="String.html" title="java.lang 中的类">String</A> charsetName)</CODE><BR> 构造一个新的 <tt>String</tt>,方法是使用指定的字符集解码字节的指定子数组。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="String.html#String(byte[], java.lang.String)">String</A></B>(byte[] bytes, <A HREF="String.html" title="java.lang 中的类">String</A> charsetName)</CODE><BR> 构造一个新的 <tt>String</tt>,方法是使用指定的字符集解码指定的字节数组。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="String.html#String(char[])">String</A></B>(char[] value)</CODE><BR> 分配一个新的 <code>String</code>,它表示当前字符数组参数中包含的字符序列。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="String.html#String(char[], int, int)">String</A></B>(char[] value, int offset, int count)</CODE><BR> 分配一个新的 <code>String</code>,它包含来自该字符数组参数的一个子数组的字符。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="String.html#String(int[], int, int)">String</A></B>(int[] codePoints, int offset, int count)</CODE><BR>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?