StringBuffer

A thread-safe, mutable(易变的,可变的)sequence of characters(字符序列). A string buffer is like aString, but can bemodified(修改). At any point in time it contains someparticular(特殊的,详细说明的)sequence of characters, but the length and content of the sequence can be changed throughcertain(某些,某几个)methodcalls(调用).

String buffers are safe for use bymultiple threads(多线程). The methods aresynchronized(同步的)wherenecessary(必要,需要)so that all theoperations(操作,运作)on any particular instance<wbr><span style="color:rgb(237,28,36)">behave(行为,<span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">表现</span><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">)</span></span>as if(就像) they<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">occur(发生,出现)</span></strong>in<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">some serial order(串行顺序)</span></strong>that is<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">consistent(一致的)</span></strong>with the order of the method calls made by each of the<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">individual<wbr>threads(单个线程)</wbr></span></strong><wbr><strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">involved(涉及的)</span></strong>.</wbr></wbr>

Theprincipal(首要的,主要的)operations on aStringBufferare theappendandinsertmethods, which areoverloaded(超载的,重载)so as toaccept(接受)data of any type. Eacheffectively(有效的)convertsa given datum(一个给定的数据)to a string and then appends or inserts the characters of that string to the string buffer. Theappendmethodalways(一直,永远)adds these characters at theend(末尾)of the buffer; theinsertmethod adds the characters at a specified point.

For example, ifzrefers(参考,引用)to a string buffer object whose current contents are "start", then the method callz.append("le")would cause(会使,会引起)the string buffer to contain "startle", whereasz.insert(4, "le")would alter the string buffer to contain "starlet".

In general(通常), if sb refers to an instance of aStringBuffer, thensb.append(x)has the sameeffect(效果)assb.insert(sb.length(),<wbr>x)</wbr>.

Whenever anoperation occurs(操作时)involving(涉及,包括)asource sequence(源序列)(such as appending or inserting from a source sequence) this class synchronizesonly(只有)on the string bufferperforming(执行)the operation, not on the source.

Every string buffer has acapacity(容量). As long as the length of the character sequence contained in the string buffer does not exceed(超过) the capacity, it is not necessary to allocate(分配,指定) a newinternal(内部的)buffer array. If the internal bufferoverflows(溢出,充满), it isautomatically(自动的)made larger. As ofrelease(发布,释放)JDK 5, this classhas been(已经)supplemented(被补充的,补充的)with an equivalent classdesigned(设计)for use by a single thread,StringBuilder. TheStringBuilderclass shouldgenerally(通常,一般的)be used inpreference to this one(优先使用), as it supports all of the same operations but it is faster, as itperforms<wbr><strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">no synchronization(不执行同步)</span></strong>.</wbr>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值