title: How to convert HashMap to TreeMap
body: <p>This question seems to be very popular and yet I couldn't get correct results for my implementation. I had this <a href="https://stackoverflow.com/questions/19512850/java-putting-hashmap-into-treemap">thread</a> as an example but so far no luck.</p>
  
  <p>Here I have HashMap that I need to convert to TreeMap in order to have key values sorted:</p>
  
  <pre><code>HasMap&lt;String, HashMap&lt;String, SomeBean&gt;&gt; hashMap = (HashMap&lt;String, HashMap&lt;String, SomeBean&gt;&gt;)request.getAttribute("HASHMAP");
  </code></pre>
  
  <p>After applying iterator I could see results in unsorted order.</p>
  
  <p>Now I want to convert it to TreeMap:</p>
  
  <pre><code>TreeMap&lt;String, TreeMap&lt;String, SomeBean&gt;&gt; treeMap = new TreeMap&lt;String, TreeMap&lt;String, SomeBean&gt;&gt;(hashMap);
  </code></pre>
  
  <p>Result: </p>
  
  <pre><code>The constructor TreeMap&lt;String,TreeMap&lt;String,SomeBean&gt;&gt;(HashMap&lt;String,HashMap&lt;String,SomeBean&gt;&gt;) is undefined
  </code></pre>
  
  <p>Well, it seems because i have nested map with my bean class it is not allowing me to create  new tree map. It is understandable as I don't expect TreeMap to have constructor that suits my criteria but the question is how do I find workaround for this problem?</p>