StringBuffer Api

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014338530/article/details/87971452
    @Test
    public void myStringBuffer(){
        StringBuffer sb = new StringBuffer("hello");
        /** append(string s) 将制定s串追加到stingbuffer之后*/
        System.out.println(sb.append(" world!"));//hello world!
        /** reverse() 将制定字符串翻转*/
        System.out.println(sb.reverse());//!dlrow olleh
        /** delete(int start,int end) 删除制定部分的子串*/
        System.out.println(sb.delete(2, 3));//!drow olleh
        /** insert(int index,参数类型 参数) 将参数,插入之字符串的index位置
         *  参数类型可以是基本数据类型,也可以是对象,集合,数组等
         */
        System.out.println(sb.insert(2,"&"));//!d&row olleh
        //字符
        System.out.println(sb.insert(2,'A'));//!dA&row olleh
        //double
        System.out.println(sb.insert(2,3.141592657000));//!d3.141592657A&row olleh
        //long
        long l = 123456789123456789l;
        System.out.println(sb.insert(2,l));//!d1234567891234567893.141592657A&row olleh
        //数组
        String[] str = new String[]{"qwe","asd","zxc"};
        System.out.println(sb.insert(2,str));//!d[Ljava.lang.String;@5c8da9621234567891234567893.141592657A&row olleh
        /** replace(int start,int end,string str) 将从start到end,换为str*/
        System.out.println(sb.replace(0,15,"HHHHH"));

    }

猜你喜欢

转载自blog.csdn.net/u014338530/article/details/87971452