java.lang.StringBuffer浅析

该类被final修饰,所以不能被继承,并且继承了AbstractStringBuilder,实现了java.io.Serializable, CharSequence两个接口。
构造方法:public StringBuffer(){
super(16) ;
}
public StringBuffer(int capacity); 初始化stringbuffer容量
public StringBuffer(String str); //用字符串初始化StringBuffer.代码实现是先构建个容量为str.length+16的空stringbuffer,然后将str添加进stringbuffer.所以构造的stringbuffer大小比str大16
public StringBuffer(CharSequence seq); 类似用string初始化
public synchronized int length(); 获取字符串长度
public synchronized int capacity(); 获取stringBuffer容量
public synchronized void ensureCapacity(int minimumCapacity) //确保容量最小为minimumCapacity
public sysnchronized void trimToSize(); //调用父类trimToSize

public synchronized void setLength(int newLength) ;//重新设置长度为newLength

public synchronized char charAt(int index) ;//返回value[index] 返回指定位置的字符

public synchronized int codePointAt(int index) ; //返回指定位置字符的编码

public synchronized int codePointBefore(int index) ;//指定位置之前的一个字符的编码

public synchronized int offsetByCodePoints(int index, int codePointOffset); //返回从index开始codePointOffset处的字符索引

public synchronized void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin); //将该stringbuffer从srcBegin到srcEnd范围内的子串复制到目的字符数组dst中,并且复制过去的字符串在dst中的起始位置是dstBegin。

public synchronized void setCharAt(int index, char ch);//将指定位置的字符设置成ch

public synchronized StringBuffer append(Object obj);//将obj以字符串形式添加到stringbuffer

public synchronized StringBuffer append(String str);// 添加字符串

public synchronized StringBuffer append(StringBuffer sb); //添加StringBufferf

public StringBuffer append(CharSequence s) ;//添加字符序列

public synchronized StringBuffer append(CharSequence s, int start, int end);//将字符序列s从start到end之间子串添加到stringbuffer

public synchronized StringBuffer append(char[] str) ;//添加一个字符数组

public synchronized StringBuffer append(char[] str, int offset, int len);// str从offset开始,长度为len的字符添加到stringbuffer

public synchronized StringBuffer append(boolean b);//添加布尔值

public synchronized StringBuffer append(char c);//添加字符

public synchronized StringBuffer append(int i);//添加整数

public synchronized StringBuffer appendCodePoint(int codePoint);//根据ASCII吗添加字符

public synchronized StringBuffer append(long lng); 添加整数

public synchronized StringBuffer append(float f);添加浮点数

public synchronized StringBuffer append(double d);添加双精度浮点数

public synchronized StringBuffer delete(int start, int end);删除范围内的子串

public synchronized StringBuffer deleteCharAt(int index);删除指定位置的字符

public synchronized StringBuffer replace(int start, int end, String str);start–end之间的子串用str替换

public synchronized String substring(int start);获取从start开始到结束的子串

public synchronized CharSequence subSequence(int start, int end);获取范围内 的字符序列

public synchronized String substring(int start, int end);获取范围内的子串

public synchronized StringBuffer insert(int index, char[] str, int offset, int len); 从index开始插入str的子串,str的子串为从offset开始,长度为len的子串

public synchronized StringBuffer insert(int offset, Object obj) ;在指定索引处插入Obj

public synchronized StringBuffer insert(int offset, String str) ;在指定索引处插入字符串

public synchronized StringBuffer insert(int offset, char[] str) ; 在一定索引处插入字符数组

public StringBuffer insert(int dstOffset, CharSequence s) ; 插入s

public synchronized StringBuffer insert(int dstOffset, CharSequence s, int start, int end);在指定位置开始,插入s的子串:从start开始,end之前的子串

public StringBuffer insert(int offset, boolean b);指定位置插入布尔值

public synchronized StringBuffer insert(int offset, char c) ;指定位置插入字符

public StringBuffer insert(int offset, int i) ;指定位置插入整数

public StringBuffer insert(int offset, long l);指定位置插入长整型

public StringBuffer insert(int offset, float f);指定位置插入浮点型

public StringBuffer insert(int offset, double d);指定位置插入双精度浮点型

public int indexOf(String str);返回字符串str的索引

public synchronized int indexOf(String str, int fromIndex);返回字符串str从fromindex开始出现在stringbuffer中的索引

public int lastIndexOf(String str) ;返回子串str最后的索引

public synchronized int lastIndexOf(String str, int fromIndex);从fromindex开始,返回str最后的索引

public synchronized StringBuffer reverse();将stringbuffer反转

public synchronized String toString();

你可能感兴趣的:(源码,java,字符串)