title: Sorting a collection of HashSets
body: <p>I apologize if this is a duplicate, but I couldn't find any answer that specifically answered this particular issue.</p>
  
  <p>I have a HashMap that contains a string key paired with a Set value.  I want to sort the values in my map based on the length of the set.  Consider:</p>
  
  <pre><code>HashMap&lt;String, Set&lt;String&gt;&gt; myMap;
  </code></pre>
  
  <p>Contains:</p>
  
  <pre><code>{"A", {"Dukmerriot", "King", "Pumpkin"}}  
  {"B", {"Steve"}}
  {"C", {"Jib", "Jab", "John", "Julie"}}
  {"D", {"Apple", "Amy", "Unicorn", "Charlie", "Raptor"}}
  {"E", {}}
  </code></pre>
  
  <p>I want to be able to get the list <code>{"D", "C", "A", "B", E"}</code> (which designates the order of the sets from largest to smallest)  from <code>myMap</code> efficiently. </p>
  
  <p>Is there a way to sort a collection of sets based on their length other than creating a wrapper class that implements Set and overriding the <code>compareTo</code> method?</p>
  
  <p>EDIT: I should specify that I don't NEED to use a HashMap to maintain this collection.  I could use a TreeMap or something, but I'm not sure if that's possible since Set doesn't implement Comparable.</p>