关闭

String StringBuffer StringBuilder

标签: javastringstringbufferstringbuilder
101人阅读 评论(0) 收藏 举报
分类:

The String class represents character string. All string literals in java program are implemented as instances of this class. 

Strings are constant, their values cannot be changed after they are created. Because String objects are immutable, they can be shared.

String concatenation is implemented through the StringBuilder and StringBuffer class and its append method.

Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.


StringBuffer class is a thread-save, mutable sequence of characters. A string buffer is like a string, but can be modified. String buffers are safe to 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.


StringBuilder is also 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, as it supports all of the same operations but it is faster, as it performs no synchronization.



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1812次
    • 积分:78
    • 等级:
    • 排名:千里之外
    • 原创:6篇
    • 转载:0篇
    • 译文:0篇
    • 评论:2条
    文章分类
    最新评论