【发布时间】:2013-02-13 13:42:33
【问题描述】:
我正在从文件中读取数据:
Some Name;1|IN03PLF;IN02SDI;IN03MAP;IN02SDA;IN01ARC
Some Other Name;2|IN01ALG;IN01ANZ
Another Name;3|
Test Testson;4|IN03MAP;IN01ARC;IN01ALG
我从该文件中读取的每一行都使用 string.split(),如下所示:
String args[] = line.split("\\|");
String candidatArgs[] = args[0].split(";");
if (args[1] != "" || args[1] != null) {
String inscrieriString[] = args[1].split(";");
事情是:当我在.split("\\|") 之后到达Another Name;3| 时,第二部分(args[1])应该是空的,null 或""(我真的不知道)。
但是我在if (args[1] != "" || args[1] != null) 上得到一个数组索引越界错误(同样,在:Another Name;3|)
【问题讨论】:
-
从您发布的示例数据中可以获得长度为 1 的
String.split数组。您需要在代码中对此进行边界检查。
标签: java string-split