title: Groovy: sort hash keys by values value
body: <p>I want to sort a hash of key->value by the values , and get the list of the sorted keys.  </p>
  
  <p>This seems to work:</p>
  
  <pre><code>groovy&gt; def map = [a:5, b:3, c:6, d:4].sort { a, b -&gt; a.value &lt;=&gt; b.value }.keySet() 
  groovy&gt; println map 
  
  [b, d, a, c]
  </code></pre>
  
  <p>but will it always work? 
  I don't know if the iterator that builds the keySet() will always iterate them by order.</p>
  
  <p>Thanks!</p>