我正在尝试解析一些管道分隔的记录。我有这个代码:
public class Test {
public static void main(String[] args) throws Exception {
String[] components = "EN|1056209|||KA3NDL|L|||||||||||||||||||||".split("\\|");
System.out.println(java.util.Arrays.toString(components));
}
}
你会期望它打印出来:
[EN, 1056209, , , KA3NDL, L, , , , , , , , , , , , , , , , , , , , , ]
但事实并非如此。它打印:
[EN, 1056209, , , KA3NDL, L]
访问数组的length
属性components
表明它正在正确打印。
有人知道为什么这是/一种解决方法吗?
编辑:
这有效:
public class Test {
public static void main(String[] args) throws Exception {
String[] components = "EN|1056209|||KA3NDL|L|||||||||||||||||||||".split("\\|", -1);
System.out.println(java.util.Arrays.toString(components));
}
}