2013-04-29 4 views
-1

LinkedHashMap을 사용하여 Excel 파일의 데이터를 읽고 mysql 테이블에 저장합니다! 내림차순 ID를 사용하여 데이터를 저장하도록 LinkedHashMap을 정렬 할 수 있습니까? 여기 내 엑셀 파일의 예이다 :ID를 사용하여 LinkedHashMap 정렬

ID 이름 연봉
50 크리스틴 2,349,000
43 폴리나 1,245,874
54 로라 4,587,894

아래 코드 저장소에 대한 인 엑셀 파일의 데이터 인 표!

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; 

     } 
+3

를 기반으로하기 때문에

LinkedHashMap<Integer, String> map = new LinkedHashMap <Integer, String>(); /* add elements here */ Set<Integer> keys = new TreeSet<Integer>(); keys.addAll(map.keySet()); 

Set<Integer> keys 지금 정렬 된 순서로 모든지도 키를 포함 : 당신이 대신 수행 할 수있는

예를 들어, 모든 키를 추출하고 분류입니다 가능한 중복 [Sorting LinkedHashMap] (0120)을 참조하십시오. – durron597

+1

@AndrewThompson 그는 검색 상자에 "linked linkedhashmap"을 입력하지 않았습니다. – durron597

+0

나는 treeMap에 대해 읽은 다음 분리 기호 그러나 나는 무언가를 성공시키지 못했습니다! 왜 내가 여기서 묻고 있습니까? – dedmar

답변

1

따르면 to the documentation, 당신이 정말로 순서를 변경할 수 있도록이지도에 추가되는 순서의 LinkedHashMap "일반적으로"저장 키를 누릅니다. TreeSet의 저장 요소의 자연 순서