String的spit方法切割字符串后的情况分析


    public  void  testStringSpit(){
        String s1 ="_500";
        String s2 ="1_500";
        String s3 ="500_";
        String[] s11 = s1.split("_");
        String[] s22 = s2.split("_");
        String[] s33 = s3.split("_");
        for (int i = 0; i < s11.length; i++) {

            System.out.println("s11:"+s11[i]);
        }
        for (int i = 0; i < s22.length; i++) {

            System.out.println("s22:"+s22[i]);
        }
        for (int i = 0; i < s33.length; i++) {

            System.out.println("s33:"+s33[i]);
        }
    }

最终结果
s11:
s11:500
s22:1
s22:500
s33:500

由上可知:
当切割符后面无字符时,不会添加空字符串。反之,切割符前无字符,则会添加一个空字符串

上一篇:用GUI画图


下一篇:半佛仙人,他从不买水军,凭什么一年内做到B站500万粉丝?