I'm trying to simplify the following code.
while(results.next())
for(String column : colNames){
if(EmptyUtil.isEmpty(results.getString(column))) {
emptyCount++;
}
}
if(emptyCount == colNames.size()){
break;
}
}
My main goal is to read a CSV file until an empty row and finish reading the file from there. And it's a necessity that I have to use this Csvjdbd driver ).
In the above code, results
is a CsvResultSet
(I've used Csvjdbc library to get this result set ). This CsvResultSet represents a single row in the CSV file inside the for loop. Basically I'm going through every row in the CSV file
b
colNames
is the column headers list in the CSV. By using results.toString(column)
, I can get the value in the particular cell in the row.
If all the cells are empty in the row, I should break from the while loop.
The above code works as expected. I just need to know how to simplify that more.