I am reading a csv file. One of the requirements is to check if a certain column has a value or not. In this case I want to check the value in array[18]. However, I am getting
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 18
Is there any other way to check the array index if it has a value or empty?
My code:
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
}
}
}
record.length - 1 == 18