I'm performing a fairly unique CSV file reading but there is one unique aspect. If the row has a blank cell value only in the 19th column, it is OK to go into the hashmap. If any other column in the row has a blank cell, it should be excluded from the hashmap. The table has 22 total columns. Is there any way to write this if statement without writing out each and every column index? For example if(piecesOfInfo[0] != "" && piecesOfInfo[1] != ""...)
public HashMap<String,String[]> createHashMap() {
File flightFile = new File("fying.csv");
HashMap<String,String[]> flightsMap = new HashMap<String,String[]>();
try {
Scanner s = new Scanner(flightFile);
while (s.hasNextLine()) {
String info = s.nextLine();
String [] piecesOfInfo = info.split(",");
if(/**piecesOfInfo contains no blanks aside from the 18th column**/){
String flightKey = piecesOfInfo[4]; //Setting the Key
String[] values = Arrays.copyOfRange(piecesOfInfo, 0, piecesOfInfo.length);
flightsMap.put(flightKey, values);
}
}
s.close();
}
catch (FileNotFoundException e)
{
System.out.println("Cannot open: " + flightFile);
}
return flightsMap;
}