I have managed to make a program where I would read data from excel files and store them in tables in mysql. My program read the first row of each file create the fields for the tables and store the rest data as values in each columns. Just because that happen programmatically I have choosed to read all the values using LinkedHashMap. Everything works fine. But when I finished and test my program I get an error in my console. The error is by LinkedHashMap because if the map previously contained a mapping for the key, the old value is replaced by the specified value.
The code for parsing the data is the below:
private static List<TableRow> parseExcelColumnData(List sheetData) {
// read each row from 1 to the last
ArrayList<TableRow> tousRows = new ArrayList<TableRow>();
for (int rowCounter = 1; rowCounter < sheetData.size(); rowCounter++) {
List list = (List) sheetData.get(rowCounter);
LinkedHashMap<String, Integer> tableFields = new LinkedHashMap(list
.size());
String str;
String[] tousFields = new String[list.size()];
int i = 0;
Cell cell = (Cell) list.get(0); // get the first column
long currentID = (long) cell.getNumericCellValue();
for (int j = 0; j < list.size(); j++) { //get the rest
cell = (Cell) list.get(j);
if (cell != null) {
if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
...
...............
}
}
}
tousRows.add(new TableRow(currentID, tableFields));
}
return tousRows;
}
Could anyone help how could I make the "tableFields" an ArrayList so as not to replace the old value?
Map<KeyType, List<ValueType>>