• StringBuffer 方法


        //append   字符串拼接的方法
            StringBuffer stringBuffer = new StringBuffer("我爱中国!");
            StringBuffer stringBuffer2 = stringBuffer.append("我爱故乡!");
            System.out.println(stringBuffer2);
            //charAt  获取指定索引处的字符 
            StringBuffer stringBuffer3 = new StringBuffer("I LOVE CODE");
            char c = stringBuffer3.charAt(2); 
            System.out.println(c);
            //setCharAt  将指定索引处的字符替换为相应的字符
            StringBuffer stringBuffer4 = new StringBuffer("I LOVE CODE");
            stringBuffer4.setCharAt(0, 'Y');
            System.out.println(stringBuffer4);
            //insert 往指定的位置插入相应的字符
            StringBuffer stringBuffer5 = new StringBuffer("12345678");
            for (int i = stringBuffer5.length()-3; i > 0 ; i = i-3) {
                stringBuffer5.insert(i, ',');
            }
            System.out.println(stringBuffer5);
            //delete   删除从指定位置开始   到指定位置结束的字符串
            StringBuffer stringBuffer6 = new StringBuffer("My Name Is Not ChenChuanYin");
            stringBuffer6.delete(11, 15);
            System.out.println(stringBuffer6);
            //replace 将指定索引位置开始位置到结束索引位置结束之间的字符转   用相应的字符串替换
            StringBuffer stringBuffer7 = new StringBuffer("My SEX IS WOMAN");
            stringBuffer7.replace(10, 15, "MAN");
            System.out.println(stringBuffer7);
        
        //reverse 将字符串倒序输出
        StringBuffer stringBuffer8 = new StringBuffer("12321");
        StringBuffer stringBuffer9 = stringBuffer8.reverse();
        System.out.println(stringBuffer9);
  • 相关阅读:
    前端数组去重
    前端三栏布局
    JS运行三部曲(预编译)
    前端常用开发工具
    前端性能监控你会监控哪些数据? 如何做?
    H5与客户端交互的方式有哪些? 怎么做?
    http协议的状态码400,401,403,404,500,502,503,301,302等常见网页错误代码
    随笔记录
    Browser Events 常用浏览器事件
    MYSQL 索引的优点
  • 原文地址:https://www.cnblogs.com/xiaolei121/p/5728055.html
Copyright © 2020-2023  润新知