现在的位置: 首页 > 综合 > 正文

Strings

2013年02月23日 ⁄ 综合 ⁄ 共 1998字 ⁄ 字号 评论关闭

The String class represents character strings. All string literals字面值 in Java programs, such as "abc", are implemented作为 as instances of实例 this class.

Strings are constant常量; their values cannot be changed after they are created. String bufferssupport缓冲 mutable可变的 strings. Because String objects are immutable不可变 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 class String includes methods for examining检查 individual单个 characters of the sequence, for comparing比较 strings, for searching搜索 strings, for extracting提取 substrings子字符串, and for creating a
copy of a string字符串副本
 with all characters translated转换 to uppercase or to lowercase. Case mapping大小写映射 is based on the Unicode Standard version标准版specified指定 by the Character class.

The Java language provides提供 special特别 support for the string concatenation串联 operator字符串 ( + ), and for conversion of转换 other objects to strings. String concatenation串联 isimplemented实现 through
the StringBuilder(or StringBuffer) class and its append method. Stringconversions转换 are implemented实现 through the method toString, defined by由,决定 Object and inherited继承 by all classes in Java.
For additional更多 information on stringconcatenation串联 and conversion转换, see Gosling, Joy, and Steele, The Java Language Specification.

Unless除非 otherwise noted另外说明, passing a null argument to a constructor构造函数 or method in this class will cause a NullPointerException to be thrown.

A String represents a string in the UTF-16 format in which supplementary characters增补字符are represented by surrogate代理 pairs (see the section Unicode Character Representations代表in the Character class for more
information). Index values refer to指的是 char code units单元, so a supplementary增补 character uses two positions位置 in a String.

The String class provides提供 methods for dealing处理 with Unicode code points (i.e., characters), in addition to those for dealing with Unicode code units (i.e., char values).

 

【上篇】
【下篇】

抱歉!评论已关闭.