String

TheStringclassrepresents(代表,表示)character strings. All string literals(字面值,文字) in Java programs, such as"abc", are implemented asinstances(实例)of this class.

Strings areconstant(常量,常数); their values cannot be changed after they are created. String buffers support(支持,维持)mutable(易变的,可变的)strings. Because String objects areimmutable(不变的,不可变的)they can beshared(共享). For example:

String str = "abc";

is equivalent to:

char data[] = {'a', 'b', 'c'}; String str = new String(data);

Here are some more examples of how strings can be used:

System.out.println("abc"); String cde = "cde"; System.out.println("abc" + cde); String c = "abc".substring(2,3); String d = cde.substring(1, 2);

The classStringincludes methods for examiningindividualcharacters of the sequence(序列的单个字符), forcomparing(比较)strings, for searching strings, for extracting(提取) substrings(子字符串), and for creating acopy of a string(字符串的副本)with(并将)all characterstranslated<wbr><strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">to(翻译)</span></strong>uppercase or to lowercase.<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">Case</span><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">mapping(大小写)</span></strong>is based on the Unicode<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">Standard version(标准版本)</span></strong>specified by the<a title="class in java.lang" href="http://blog.sina.com.cn/s/blog_a3bf7bd00100xg9j.html" style="text-decoration:none; color:rgb(65,100,111)"><code>Character</code></a>class.</wbr>

The Java languageprovides(提供,规定) special(特别的,特殊) support(支持)for the stringconcatenation(串联,连接)operator(操作员,运算符)(<wbr>+<wbr>), and for<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">conversion(转换)</span></strong>of other objects to strings. String concatenation is implemented<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">through(通过,穿过)</span></strong>the<code>StringBuilder</code>(or<code>StringBuffer</code>) class and its<code>append</code>method. String conversions are implemented through the method<code>toString</code>,<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">defined by<code>Object(是由Oeject定义)</code></span></strong>and inherited(继承) by all classes in Java. For additional(附加,额外的,有关) information on string concatenation and conversion,<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">see(查阅)</span></strong>Gosling, Joy, and Steele,<em>The Java Language Specification</em>.</wbr></wbr>

Unless(除非,如果不)otherwise(另外的,其他方面的)noted(说明,注意),passing(经过,传递)anullargument to a constructor(构造函数)or method in this class will cause aNullPointerExceptionto be thrown(抛出).

AStringrepresents a string in the UTF-16 format in whichsupplementary(补充,增补)charactersare represented bysurrogate(代理)pairs(see the sectionUnicode Character Representations(表现形式)in theCharacterclass for more information). Index valuesrefer to(指的是,参考)<wbr><code>char</code>code<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">units(单位,单元)</span></strong>, so a supplementary character<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">uses two positions(占用两个位置)</span></strong>in a<code>String</code>.</wbr>

TheStringclass provides methods fordealing with(处理)Unicode code points (i.e., characters), in addition to those for dealing with Unicode code units (i.e.,charvalues).

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值