StringBulider类

删除回忆录丶 提交于 2019-11-27 06:02:37

StringBulider类创建的字符串同样可以对字符串进行修改:

public class StringBuliderDemo {
    public static void main(String[] args) {
    StringBuilder sb = new StringBuilder();
    sb.append("1234"); //添加字符串
    sb.insert(2, "dont");//在指定位置插入,
    sb.delete(1, 4);//删除,包含头,不包含尾
    sb.replace(1, 4, "not");//替换指定范围内的内容,包含头,不包含尾
    String str = sb.toString();
    System.out.println(str);
    System.out.println(sb.reverse());//反转
    System.out.println("字符串的长度为:"+sb.length());
}
}

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!