我有点困惑
public static void main(String [] args){
String s = "a,b,c,d,";
System.out.println(s.split(",").length);
}
我期待看到 5 作为输出.. 但输出是 4?为什么它会忽略最后一个“空”字段
如果我试图解析具有(比如说)5 列的数据,我该如何处理这种情况。
cases:
a,b,c,d,e
a,,c,d,e //this case is fine as this still has 5 fields.. one of the field is missing.. but thats ok
a,b,c,d //simple length check with header catches this error
a,b,c,d,e,f //simple length check
a,b,c,d,e,// looks like there are 6 fields.. but unable to catch such error by length check