我正在阅读一个csv文件。其中一个要求是检查某个列是否有值。在这种情况下,我想检查array[18]
中的值。但是,我越来越如何检查数组[]在java中有一个空值?
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 18
是否有任何其他方式来检查数组索引,如果它有一个值或空?
我的代码:
while ((sCurrentLine = br.readLine())!= null) {
String[] record = sCurrentLine.split(",");
if(record.length > 0){ // checking if the current line is not empty on the file
if(record[18] != null){ // as per console, I am getting the error in this line
String readDateRecord = record[18];
// other processing here
}
}
}
得到数组的长度第一,你能避免IndexOutfBoundsException.Or别人赶上ArrayOutofBoundsException – Renjith
例外说,有在不元素这个阵列中的位置。向我们展示将元素添加到数组的代码。 – Kiki
'record!= null' –