StringBuilder StringBuffer String的區別(原始碼分析)-java

desaco發表於2016-03-10

》StringBuffer,執行緒安全的

public final class StringBuffer extends AbstractStringBuilder implements

        Appendable, Serializable, CharSequence {

public StringBuffer() {
       }

   public synchronized StringBuffer append(String string) {
        append0(string);
        return this;
    }

》StringBuilder,執行緒不安全的

public final class StringBuilder extends AbstractStringBuilder implements
        Appendable, CharSequence, Serializable {

public StringBuilder() {
    }

public StringBuilder append(String str) {
        append0(str);
        return this;
    }

》String,執行緒安全的

public final class String implements Serializable, Comparable<String>, CharSequence {

public String() {
        value = EmptyArray.CHAR;
        offset = 0;
        count = 0;
    }

相關文章