StringBuffer类的delete()方法和deleteCharAt()方法

public static void main(String[] args) {
        String s = "123456";
        StringBuilder s1 = new StringBuilder(s);
        StringBuffer s2 = new StringBuffer(s);
        StringBuilder s3 = new StringBuilder(s);
        StringBuffer s4 = new StringBuffer(s);
        s1.delete(0,2);
        s2.delete(0,3);
        s3.deleteCharAt(0);
        s4.deleteCharAt(1);
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println(s4);
    }

 

delete方法需要删除的头尾,两个参数;deleteCharAt一个参数,删除特定位置的字符。

 

posted @ 2020-08-04 10:44  矮方方  阅读(2062)  评论(0编辑  收藏  举报