特点: 线程安全的可变字符串。适用于字符串的拼接,同步,效率低
构造方法

  • public StringBuffer():无参构造方法
  • public StringBuffer(int capacity):指定容量的字符串缓冲区对象
  • public StringBuffer(String str):指定字符串内容的字符串缓冲区对象

常用方法;

  • public int capacity():返回当前容量。
  • public int length():返回长度(字符数)。
  • public StringBuffer append(Object str):可以把任意类型数据添加到字符串缓冲区里面,并返回字符串缓冲区本身
  • public StringBuffer insert(int offset,Object str):在指定位置把任意类型的数据插入到字符串缓冲区里面,并返回字符串缓冲区本身
  • public StringBuffer deleteCharAt(int index):删除指定位置的字符,并返回本身
  • public StringBuffer delete(int start,int end):删除从指定位置开始指定位置结束的内容,并返回本身
  • public StringBuffer replace(int start,int end,String str):从start开始到end用str替换
  • public StringBuffer reverse() 内容反转,并返回本身
  • public String substring(int start)截取开始位置start到末尾
  • public String substring(int start,int end)截取开始位置start到末尾end
  • -
posted on 2017-04-03 01:47  2637282556  阅读(338)  评论(0编辑  收藏  举报