stringbuffer
A mutable sequence of characters. This class provides an API compatible with StringBuffer, but with no guarantee of synchronization. This class is designed for use as a drop-in replacement for StringBuffer in places where the string buffer was being used by a single thread (as is generally the case). Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under most implementations.
The principal operations on a StringBuilder are the append and insert methods, which are overloaded so as to accept data of any type. Each effectively converts a given datum to a string and then appends or inserts the characters of that string to the string builder. The append method always adds these characters at the end of the builder; the insert method adds the characters at a specified point.
For example, if z refers to a string builder object whose current contents are "start", then the method call z.append("le") would cause the string builder to contain "startle", whereas z.insert(4, "le") would alter the string builder to contain "starlet".
In general, if sb refers to an instance of a StringBuilder, then sb.append(x) has the same effect as sb.insert(sb.length(), x). Every string builder has a capacity. As long as the length of the character sequence contained in the string builder does not exceed the capacity, it is not necessary to allocate a new internal buffer. If the internal buffer overflows, it is automatically made larger.
Instances of StringBuilder are not safe for use by multiple threads. If such synchronization is required then it is recommended that java.lang.StringBuffer be used.
可变字符序列。这个类提供了一个接口兼容stringbuffer,但没有担保同步。这个类是专为使用下拉替代stringbuffer地方的字符串缓冲区所使用的单线程(一般情况)。在可能的情况下,这是建议,这类优先使用stringbuffer它下会更快大多数实现。
主要业务是String Builder的添加和插入的方法,这是重载以接受任何类型的数据。每个有效地转换为一个给定的基准为一个字符串,然后添加或插入字符的字符串的字符串生成器。追加方法总是增加了这些字符结束时的建设者;插入方法添加字符在指定点。
例如,如果“是指一个字符串生成器对象的当前内容的“开始”,然后调用方法z.append(“”)将导致字符串生成器包含“startle”,而z.insert(4,“乐”)将改变字符串生成器包含“startlet”。
一般来说,如果某人”指一个String Builder,然后某人。附加(×)具有相同的效果插入(某人某人。。length(),×)。每一个字符串生成器具有容量。只要字符序列的长度包含在字符串生成器不能超过的能力,它不需要分配一个新的内部缓冲区。如果内部缓冲区溢出,它是自动取得较大。
实例Builder是不安全的使用多线程。如果这种同步是需要那么建议java.lang.stringbuffer使用。
string
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 buffers support mutable strings. Because String objects are immutable they can be shared. 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 is implemented through the StringBuilder(or StringBuffer) class and its append method. String conversions are implemented through the method toString, defined by Object and inherited by all classes in Java. For additional information on string concatenation 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).
类代表字符串的字符串。所有的字符串的程序,如“美国广播公司”,是实现这一类的实例。
字符串常数;他们不能改变他们的创造。支持可变的字符串的字符串缓冲区。因为字符串对象是不变的,它们可以共享。比如说呢。
字符串=“美国广播公司”;
相当于:
字符数据[ ] = { ' ',' ','丙' };
一个新的字符串的字符串(数据);
这里有一些例子,如何可以使用字符串:
系统提供了。(“美国广播公司”);
弦图=“光盘”;
系统提供。了。(“美国广播公司”+光盘);
字符串=“基础”子(2 , 3);
弦乐四=光盘子(1,2);
这类字符串的方法包括审查个别字符的序列,比较字符串,字符串搜索,提取子,并创建一个副本的所有字符字符串转化为大写或小写字母。案例映射是基于标准的版本,由指定的字符类。
爪哇语言提供特殊支持字符串串联运算符(+),并转化为其他对象的字符串。字符串连接是通过Builder(或stringbuffer)类及其添加方法。串的转换是通过形式定义的对象和方法,继承的所有类别中。额外的信息字符串连接和转换,看到小鹅,欢乐,和斯梯尔,该语言规范。
除非另有说明,传递一个空参数的构造函数或在这个类中的方法会造成一个空指针异常被抛出。
一个字符串,表示一个字符串在UTF - 16格式在补充字符代表代理对(请参阅字符表示的字符类的更多信息)。指数值是指字符代码的单位,所以增补字符采用双位置在一个字符串。
字符串类提供的方法处理字符代码点(即,字),除了那些处理字符代码单元(即,字符值)。