StringBuffer
是个字符串缓冲区对象,用于存储数据的容器
特点:1.长度是可变的
2.可以存储不同类型数据
3.最终要转换成字符串使用
4.可以对字符串进行修改
功能
1.添加
append(data)将指定数据添加到已有数据的结尾处
insert(位置,字符串) 将数据插入到指定位置
2.删除
delete(start,end) 删除缓冲区中的数据,包含start不包含end
deleteCharAt(ine index)删除指定位置元素
StringBuffer.delete(0,sb.length());
3.查找
char charAt(index);
int indexof(string)
int lastindexof(String);
4.修改
StringBuffer replace(start,end.String)
void setCharAt(index,char)
setlength()设置长度
5.反转
StringBuffer reverse();
6.将缓冲区中的指定数据存储到字符数组中
void getChars(int srcBegin,int srcEnd,char[] dst,int dstbegin)
StringBuilder 线程不同步的,StringBuffer是同步的。
建议使用StringBuilder效率快。
JAVA 升级 :提高效率 简化书写 提高安全性