其他分享
首页 > 其他分享> > String的spit方法切割字符串后的情况分析

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

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

标签:String,spit,int,s11,s33,s22,字符串,500
来源: https://www.cnblogs.com/xuejun-blog/p/15302360.html