1

我正在尝试根据中的值将 a 转换Map为有序的。ListMap

假设我有以下内容:

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}
4

1 回答 1

8
List<String> list = Ordering.natural().onResultOf(Functions.forMap(map))
   .sortedCopy(map.keySet());

...我认为?

于 2012-11-01T20:52:17.863 回答