나는 엑셀 파일의 데이터를 읽고 테이블에 저장하는 프로그램을 만들고있다. 하지만 Java에서 Comparators를 처음 접했을 때 나는 그 중 하나를 만드는 데 어려움을 겪고 있습니다. 여기에 내 문제는, 나는 모든 데이터를 문자열로 Excel 파일에서 읽고 테이블에 저장할 관리했습니다. 하지만 내 프로젝트는 ID를 오름차순으로 테이블에 저장하는 것입니다. 누군가 LinkedHashmaps를 비교하고 ID로 저장할 Comparator를 만들 수 있습니까? 내가 저장해야 데이터는 다음과 같다 :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