java string split 怎么保留尾部空字符串

# 不保留尾部空字符串

public class QQ {
    public static void main(String[] args) {
        String str = "a,b,c,d,";
        String[] strArr = str.split(",");
        System.out.println(JSON.toJSON(strArr));
    }
}

# 保留尾部空字符串

public class QQ {
    public static void main(String[] args) {
        String str = "a,b,c,d,";
        String[] strArr = str.split(",", -1);
        System.out.println(JSON.toJSON(strArr));
    }
}

 

posted on 2019-07-31 18:13  斜月三星一太阳  阅读(2711)  评论(0编辑  收藏  举报