I created a map and I want to sort it by the value but I need to give the output as a list of the strings only. I think I can sort the map by extending comparable and then add every sorted key to a list but I'm not sure it is the best way. Any ideas?
//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;
}