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.out.println(str1);
// }
int total = 0;
for (int i = 0; i < cntList.size(); i++) {
System.out.println(cntList.get(i).getCnt()+" "+cntList.get(i).getLetterCnt() +" letter words");
total+=cntList.get(i).getCnt();
}
System.out.println(total+" total words");
// 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.out.println(str1);
// }
int total = 0;
for (int i = 0; i < cntList.size(); i++) {
System.out.println(cntList.get(i).getCnt()+" "+cntList.get(i).getLetterCnt() +" letter words");
total+=cntList.get(i).getCnt();
}
System.out.println(total+" total words");
댓글
댓글 쓰기