我正在尝试根据Map
中的值将List
转换为有序Map
。
假设我有以下内容:
Map<String, Integer> map = Maps.newHashMap();
map.put("foo", 1);
map.put("boo", 3);
map.put("bar", 2);
//list needs to be sorted by Integer Value -- ASC or DESC
List<String> list = //Elegant guava call? List should be: {foo, bar, boo}
答案 0 :(得分:8)
List<String> list = Ordering.natural().onResultOf(Functions.forMap(map))
.sortedCopy(map.keySet());
......我想?