title: Efficient way to sort keys of hashmap Java
body: <p>Given a <code>hashMap</code> and return the keys of <code>hashmap</code> in sorted order in <code>arraylist</code>
  This is the function API:</p>
  
  <pre><code>ArrayList&lt;String&gt; foo(HashMap&lt;String,String&gt; hashMap)
  {
  }
  </code></pre>
  
  <p>Now, there are two ways to solve problem:  </p>
  
  <blockquote>
    <ol>
    <li>Take all keys in arraylist and then sort it  </li>
    <li>Store the keys of map in treeset and then store in arraylist and return.</li>
    </ol>
  </blockquote>
  
  <p>Former approach will not uses additional space complexity as i am not using   treeset. The keys are alphanumeric. Which one will have less time complexity.
  Any other way you would recommend? </p>