3

Suppose I have a java.util.HashMap object. I want to produce a List in which the entries in the HashMap are sorted high to low by the value of the Double. How do I do it? I've made a stab at it in Java using the Guava Ordering class, but I don't like the aesthetics of jumping from xtend to Java and, besides, it isn't working :( I have the sense that this should be easy in xtend using lambda expressions, but I can't figure out how to do it.

Thanks.

mathlawguy
  • 326
  • 1
  • 8

1 Answers1

4
val source = newHashMap('one' -> 1.0 , 'two' -> 2.0)
source.entrySet.sortBy[-value]           // List<Map.Entry<String, Double>>

or if you only want the keys

source.entrySet.sortBy[-value].map[key]  // List<String>
Sven Efftinge
  • 3,065
  • 17
  • 17