java string split how to retain the tail of an empty string

# Tail does not retain an empty string

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));
    }
}

# Retain the tail of an empty string

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));
    }
}

 

Guess you like

Origin www.cnblogs.com/lwmp/p/11278170.html