我從一個文件中讀取數據:如何驗證是否string.split()返回null
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("\\|")
第二部分(args[1]
)後達到Another Name;3|
應該是空的,要麼null
或""
(我真的不知道)。
然而我對if (args[1] != "" || args[1] != null)
得到一個數組索引越界錯誤的(再次,在:Another Name;3|
)
從您發佈的示例數據中可以得到長度爲1的'String.split'數組。您需要在代碼中對此進行綁定檢查。 – Perception 2013-02-13 13:46:21