搜课云网 > 上海跑赢职场 > 资讯总汇 > 容器通常具备一些固定的方法

容器通常具备一些固定的方法

机构:上海跑赢职场 时间:2016-04-06 10:18:17 点击:916

  容器通常具备一些固定的方法:

  1,添加。 StringBuffer append(data):在缓冲区中追加数据。追加到尾部。

  StringBuffer insert(index,data):在指定位置插入数据。

  2,删除。 StringBuffer delete(start,end);删除从start至end-1范围的元素

  StringBuffer deleteCharAt(index);删除指定位置的元素

  //sb.delete(0,sb.length());//清空缓冲区。

  3,修改。 StringBuffer replace(start,end,string);将start至end-1替换成string void setCharAt(index,char);替换指定位置的字符 void setLength(len);将原字符串置为指定长度的字符串 4,查找。(查不到返回-1)

  int indexOf(string); 返回指定子字符串在此字符串中第一次出现处的索引。 int indexOf(string,int fromIndex);从指定位置开始查找字符串

  int lastIndexOf(string); 返回指定子字符串在此字符串中最右边出现处的索引。

  int lastIndexOf(string,int fromIndex); 从指定的索引开始反向搜索 5,获取子串。 string substring(start); 返回start到结尾的子串

  string substring(start,end); 返回start至end-1的子串 6,反转。

  StringBuffer reverse();字符串反转

  更多关于Java编程的资讯,请访问上海Java编程培训学校

下一篇:字符串的方法
师资介绍