Translation_java_StringBuffer

_ 代表要翻译 此颜色代表上文已翻译

(%) %解释下划线 此颜色代表翻译词组


java.lang
Class StringBuffer

java.lang.Object
java.lang.StringBuffer
All Implemented Interfaces:
Serializable, Appendable, CharSequence

public final class StringBuffer
extends Object·1
implements Serializable, CharSequence

A thread-safe, mutable(易变的)sequence(一连串)of characters. A string buffer is like a String, but can be modified(修改的). At any point in time(同时)it contains(包含)some particular(特殊)sequence of characters, but the length and content of the sequencecan be changed through certain(某些)method calls.

stringbuffer是一个安全的线程,可以改变的字符串,一个stringbuffer就像一个字符串,
但是可以被修改。在有任何点的同时它还包含了字符串,但是字符串的长度和连接通过某些方法被修改;

String buffers are safe for use by multiple(多线程)threads. The methods are synchronized where necessary so thatall the operations(运行)on any particular(特定的)instance(事例)behave(使用) as ifthey occur(出现)in some serial order(连续的下命令)that is consistent(一致的)with the order(次序)of the method calls made byeach of the individual(个人的)threads involved.

通过使用stringbuffer的多线程是安全的,它的所有方法是同步的在需要的时候;以至于运行事例使用的同时
如出现多个命令,通过单线程对它下的命令顺序是一致的

The principal(主要的) operations(操作)on a StringBuffer 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 stringto the string buffer. The append method always adds these charactersat the end of the buffer; the insert method adds the characters at a specified(规定)point.

stringbuffer主要的操作有append和insert方法,它是被重载的,所以能接受任何数据类型.任何转换成string的数据和string的appends或者inserts是到stringbuffer
这append的方法总是在buffer后面加这些字符,这insert方法是在这规定的点上加字符

For example, if z refers(指)to a string buffer object whose current(流行的)contents are "start", then the method call z.append("le") would cause(给...带来)the string buffer to contain "startle", whereas z.insert(4, "le") would alter the string buffer to contain "starlet".

例如,假如z是"start"的stringbuffer对象,
然后调用这个append方法加("le") 得到的stringbuffer结果包含:"startle";
而z调用这个insert插入方法(4,"le")修改后得到的stringbuffer结果包含:"startle";

In general(总体), if sb refersto an instance(例子)of a StringBuffer, then sb.append(x) has the sameeffect assb.insert(sb.length(), x).

总体看:假如sb是指一个stringbuffer的,然后sb.append(x)和sb.insert(sb.length(),x)得到是相同的结果

Whenever an operation(操作) occurs(重新)involving(使..陷于)a source(原来的)sequence (such as appending or inserting from a source sequence) this class synchronizes only on the string buffer performing(进行)the operation, not on the source.

任何一个操作这个stringbuffer类的同步操作,得到是一个新的顺序,而不是原来的

Every string buffer has a capacity(容量). As long asthe length of the character sequence contained(包含)in the string buffer does not exceed(超越)the capacity, it is not necessary to allocate(分配)a new internal(内部)buffer array. If the internalbuffer overflows(溢出), it is automatically(自动的)made larger. As of release(发布)JDK 5, this class has been supplemented(补充)with an equivalent class designed(原有的)for use by a single thread, StringBuilder. The StringBuilder class should generally(广泛的)be used in preference(优先)to this one, as it supports(支持)all of the same operations(操作)but it is faster, as it performsno synchronization.

每个stringbuffer有一个容量大小,在这stringbuffer只要这个字符串不超越这个容量,
它是不需要分配一个新的内存容量,假如这内存是溢出的,它是会自动增长的.由于发布了JDK1.5,
这个类已经修补了我们原有使用的单线程,stringbuilder.它是优先于stringbuffer被广泛的使用,
它是支持所有的相同的操作而且是非常快,所以它不之多同步的。

Since:
JDK1.0
See Also:
StringBuilder, String, Serialized Form

你可能感兴趣的:(StringBuffer)