我正在制作一个程序来读取excel文件中的数据并将它们存储在表中。但是因为我是Java新手,所以在编写其中一个时遇到了困难。这是我的问题,我已经设法从excel文件中读取所有数据作为字符串并将它们存储在一个表中。但我的项目是通过升序ID将它们存储在表格中。有人可以帮助我创建一个比较器来比较LinkedHashmaps并通过它们的ID存储它们吗? ,我要存储的数据是像下面:LinkedHashMap的比较器
ID Name Salary
50 christine 2349000
43 paulina 1245874
54 laura 4587894
用于分析数据的代码是以下:
private static LinkedHashMap parseExcelColumnTitles(List sheetData) {
List list = (List) sheetData.get(0);
LinkedHashMap < String, Integer > tableFields = new LinkedHashMap(list.size());
for (int j = 0; j < list.size(); j++) {
Cell cell = (Cell) list.get(j);
tableFields.put(cell.getStringCellValue(), cell.getCellType());
}
return tableFields;
}
private static LinkedHashMap[] parseExcelColumnData(List sheetData) {
LinkedHashMap[] tousRows = new LinkedHashMap[sheetData.size() - 1];
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;
for (int j = 0; j < list.size(); j++) {
Cell cell = (Cell) list.get(j);
if (cell != null) {
if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
tableFields.put(String.valueOf(cell
.getNumericCellValue()), cell.getCellType());
} else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
tableFields.put(cell.getStringCellValue(), cell
.getCellType());
} else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
tableFields.put(String.valueOf(cell
.getBooleanCellValue()), cell.getCellType());
}
}
}
tousRows[rowCounter - 1] = tableFields;
}
return tousRows;
}
什么是(键,值)对你的地图? – NINCOMPOOP 2013-04-30 07:12:34