String StringBuffer StringBuilder
2016-04-18 11:27
344 查看
Stringis immutable,
if you try to alter their values, another object gets created, whereas
StringBufferand
StringBuilderare mutable so
they can change their values.
Thread-Safety Difference:
The difference between
StringBufferand
StringBuilderis
that
StringBufferis
thread-safe. So when the application needs to be run only in a single thread then it is better to use
StringBuilder.
StringBuilderis
more efficient than
StringBuffer.
Situations:
If your string is not going to change use a String class because a
Stringobject
is immutable.
If your string can change (example: lots of logic and operations in the construction of the string) and will only be accessed from a single thread, using a
StringBuilderis
good enough.
If your string can change, and will be accessed from multiple threads, use a
StringBufferbecause
StringBufferis
synchronous so you have thread-safety.
相关文章推荐
- 232. Implement Queue using Stacks
- iOS中UIActionSheet使用详解
- RequireJS学习资料
- 建造(Builder)模式
- com.ibatis.common.beans.ProbeException: There is no READABLE property named 'baiduIndex' in class 'j
- SoapUI接口测试实例(webservice接口)
- cordova build android 补充
- 解决办法:Access restriction: The type JPEGImageEncoder is not accessible due to restriction
- Mysql错误:Ignoring query to other database解决方法
- MongoVUE模糊查询,更新单个字段
- UIPresentationController简介
- ORA-01789: query block has incorrect number of result columns
- web.xml is missing and <failOnMissingWebXml> is set to true[解决]
- requireJS
- UITextField详解
- flashback query
- IOS Could not build module 'foundation'
- DuiLib学习-DuiLib中的通知事件
- UGUI(七)界面拖动和焦点界面
- ibatis的isNotNull isNotEmpty isEques