public static void main(String[] args) { String str = "a,b,c,,d,e,,,,,,,,"; String[] arr = str.split(","); System.out.println(); }
可以看到后面的空字符串丢失了!!!
解决办法:
public static void main(String[] args) { String str = "a,b,c,,d,e,,,,,,,,"; String[] arr = str.split(",",-1); System.out.println(); }
看到没有,使用 String[] arr = str.split(",",-1); 分割的空字符串就没有丢失了!