4.StringBuffer & StringBuilder

2019-06-25  本文已影响0人  木有鱼丸啦
1.StringBuffer 继承了 AbstractStringBuilder 实现了 Serializable, CharSequence ,所有的方法都是synchronized线程安全的,方法基本继承自父类AbstractStringBuilder
extends AbstractStringBuilder  implements java.io.Serializable, CharSequence
2.StringBuilder 继承了 AbstractStringBuilder 实现了 Serializable, CharSequence。 方法基本继承自父类AbstractStringBuilder。
extends AbstractStringBuilder  implements java.io.Serializable, CharSequence
//多了两个io操作
    private void writeObject(java.io.ObjectOutputStream s)
        throws java.io.IOException {
        s.defaultWriteObject();
        s.writeInt(count);
        s.writeObject(value);
    }

    /**
     * readObject is called to restore the state of the StringBuffer from
     * a stream.
     */
    private void readObject(java.io.ObjectInputStream s)
        throws java.io.IOException, ClassNotFoundException {
        s.defaultReadObject();
        count = s.readInt();
        value = (char[]) s.readObject();
    }
上一篇下一篇

猜你喜欢

热点阅读