Java 翻译 StringBuffer

 

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 sequence can be changed through certain ( 某些 ) method calls ( 调用 ).

String buffers are safe for use by multiple threads. The methods are synchronized where necessary (必要的 ) so that all the operations on any particular instance behave as if they occur (发生 ) in some serial order that is consistent (一致的 ) with the order of the method calls made by each of the individual threads involved (涉及 ).

 

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 string to the string buffer. The append method always adds these characters at the end of the buffer; the insert method adds the characters at a specified point.

 

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 ".

 

In general (一般 ), if sb refers to an instance (实例 ) of a StringBuffer , then sb.append(x) has the same effect (效果 ) as 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.

 

Every string buffer has a capacity (容量 ). 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 new internal (内部 ) buffer array. If the internal (内部 ) buffer 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 performs no synchronization.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值