本帖最后由 VisionDo 于 2015-12-12 14:07 编辑
public final class String
extends Object
implements Serializable, Comparable<String>, CharSequence
The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class.
Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared. For example:
String str = "abc";
is equivalent to:
char data[] = {'a', 'b', 'c'};
String str = new String(data);
API:
公用不可修改类String继承自对象类,实现了可序列化,可比(与字符串可比),字符序列化
Java程序里的所有字符串常量,比如“abc”,都是该类的实例化。
字符串是常量。一旦被创建后,他们的值是不可改变的。字符串缓冲区支持可变字符串,因为字符串对象不可更改它们可以被共享。
<div class="quote"><blockquote>Class StringBuffer
java.lang.Object
java.lang.StringBuffer
All Implemented Interfaces:
Serializable, Appendable, CharSequence
public final class StringBuffer
extends Object
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 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.
公用不可修改类StringBuffer继承自对象类,实现了可序列化,可追加,可字符序列化。
它是线程安全的可变字符序列。一个String Buffer就像一个字符串,但是,它可以被更改。在任意时间点,通过调用特定的方法,可以修改String Buffer中包含的特定字符串序列的内容和长度。
在多线程中使用String Buffer是安全的。在必要的情况下,对所有特定实例的操作都是同步的,比如每个命令的执行顺序是与那些调用他们的线程的顺序是一致的。
java.lang
Class StringBuilder
java.lang.Object
java.lang.StringBuilder
All Implemented Interfaces:
Serializable, Appendable, CharSequence
public final class StringBuilder
extends Object
implements Serializable, CharSequence
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.
公用不可修改类StringBuffer继承自对象类,实现了可序列化,可追加,可字符序列化。
它是可变字符序列。该类提供了一个兼容StringBuffer的接口,但没有保证同步(个人理解为不可以在多线程中使用)。StringBuilder类被设计用来代替StringBuffer,当StringBuffer正在被被单线程使用的时候(在一般的情况)。如果可能的话,建议优先使用StringBuffer,因为StringBuffer更高效。
|