그래서 treeMap을 사용하여 데이터 컬렉션을 만든 다음 내 자신의 비교기를 사용하는 동안 정렬 된 목록을 가져 오려고합니다.내 구현에 뭔가 잘못되었습니다.
내 문제는은, Collections.sort 오류 때문에 Can only iterate over an array or an instance of java.lang.Iterable
을 던져 것입니다하지만 내 extsListed 여기 http://docs.oracle.com/javase/8/docs/api/java/util/List.html
List<FileInfo> extsListed = new ArrayList<FileInfo>(exts.values());
for (FileInfo info : Collections.sort(extsListed)) {
System.out.println(info.key + ' ' + info.count + ' ' + info.size);
}
System.out.println(totalFound.toString() + ' ' + totalSize);
}
public static class FileInfo implements Comparable<FileInfo>{
String key;
Integer count;
Long size;
public FileInfo(String key, File file){
count = 1;
this.key = key;
this.size = file.length();
}
public int compareTo(FileInfo other) {
if (this.size > other.size) return 1;
else if (this.size == other.size) {
if (this.key.compareTo(other.key) >= 1) return 1;
else if (this.key.equals(other.key)) return 0;
else return -1;
}
else return -1;
}
}
우와 우우 나는 이것을 좋아한다. 내 질문에 왜 내게 이런 것이 없었는가? +50 – ditoslav
@DominikDitoIvosevic 만약 당신이 Java 8을 사용하고 있지 않다면, 아마도 그렇게해야합니다. Java 7은 4 월에 EOL이 될 예정입니다. –
나는 약 15 시간 동안 자바로 코딩 했으므로 "java8을 사용하지 않음"과 "자바를 사용하지 않음"이 많지 않다. D는 나에게이 기능적 사용법에 대해 좀 더 알아야 할 몇 가지 구글 검색 용어를 줄 수 있겠는가? – ditoslav