11월, 2016의 게시물 표시

list sort

List<CharCount> list = new ArrayList(); // System.out.println("arraylist==>"+wordList.length); CharCount tempLetterCnt; int ord = 0; for (int i = 0; i < wordList.length; i++) { int temp = 0; tempLetterCnt = new CharCount(); if (!wordList[i].isEmpty()) { for (int j = 0; j < cntList.size(); j++) { if (wordList[i].length() == cntList.get(j).getLetterCnt()) { int cnt = cntList.get(j).getCnt(); tempLetterCnt.setCnt(cnt); tempLetterCnt.setLetterCnt(wordList[i].length()); cntList.remove(j); cntList.add(j, tempLetterCnt); temp ++; break; } } } if (cntList.isEmpty() || temp == 0) { tempLetterCnt.setCnt(0); tempLetterCnt.setLetterCnt(wordList[i].length()); cntList.add(ord++,tempLetterCnt); } } Collections.sort(cntList, LetterCnt.CntLetterComparator); //   for(CharCount str1: cntList){ // System.ou...

HashMap

Set<Integer> keys1 = hMap.keySet(); for(int key:keys1) { System.out.println(hMap.get(key)+" "+key +" letter words"); total += (int)hMap.get(key); }