数据结构---Java---String、StringBuilder、StringBuffer
2020-12-13 03:49
标签:valueof cap this 不可 nal length div ret rabl 1、概述 1.1 String:不可变字符串 1.2 StringBuilder:可改变的字符串,线程不安全 StringBuffer:可改变的字符串,线程安全 数据结构---Java---String、StringBuilder、StringBuffer 标签:valueof cap this 不可 nal length div ret rabl 原文地址:https://www.cnblogs.com/anpeiyong/p/11089175.htmlpublic final class String implements java.io.Serializable, Comparable
public final class StringBuilder extends AbstractStringBuilder implements java.io.Serializable, CharSequence{
//调用父类的构造器,再调用自己的append方法
public StringBuilder(String str) {
super(str.length() + 16);
append(str);
}
@Override
public StringBuilder append(Object obj) {
return append(String.valueOf(obj));
}
}
abstract class AbstractStringBuilder implements Appendable, CharSequence {
char[] value;
AbstractStringBuilder(int capacity) {
value = new char[capacity];
}
}
public final class StringBuffer extends AbstractStringBuilder implements java.io.Serializable, CharSequence{
//调用父类构造器,再调用自己的append方法
public StringBuffer(String str) {
super(str.length() + 16);
append(str);
}
@Override
public synchronized StringBuffer append(String str) {
toStringCache = null;
super.append(str);
return this;
}
}
文章标题:数据结构---Java---String、StringBuilder、StringBuffer
文章链接:http://soscw.com/essay/28368.html