java问题记录

字符串分割问题

如逗号分割,如果逗号之间为空,那么分割长度不够,解决方式及示例如下:

        String s2 = "a,b,,";
        String[] x = s.split(",");
        String[] x2 = s2.split(",");
        String[] x3 = s2.split(",", -1);
        System.out.println(x.length);
        System.out.println(x2.length);
        System.out.println(x3.length);

你可能感兴趣的:(java问题记录)