지도를 만들었으므로 그 값으로 정렬하고 싶지만 그 결과를 문자열 목록으로 제공해야합니다. 내가 비교할 수있는 확장하여지도 정렬 할 수 있다고 생각하고 모든 정렬 된 키 목록에 추가하지만 가장 좋은 방법인지 잘 모르겠습니다. 어떤 아이디어?지도의 값으로 문자열 목록 정렬
//code is not finished yet//
public List<String> search(String prefix) {
Map <String, Integer> suitable_sites = new LinkedHashMap<>() ;
List<String> sorted_list = new ArrayList<>();
for (Map.Entry<String, Site<String>> site :index.entrySet()) {
Map <String, Integer> words = site.getValue().getWords() ;
int counter =0 ;
for (String word : words.keySet()) {
if (word.startsWith(prefix))
counter++;
}
int weight = counter/site.getValue().getAmmount();
if (weight == 0)
continue;
suitable_sites.put(site.getKey(), weight);
}
return null;
}
http://www.mkyong.com/java/how-to-sort- a-map-in-java/ – Jay
키의 목록을 값별로 정렬해야하기 때문에 약간 다른 점이 있습니다. 필자는 도움이되는 대답을 얻었습니다. –