How to Sort Hierarchical keys of Map Collection?
<p>I am facing problem in sorting following key values list(Map). Consider sorting key as expected will solve my problem.</p>

<p>Expected Output</p>

<pre><code>Key         Value
1           animal
1.1         dog
1.1.1       tommy
1.1.2       Lily
1.1.10      Sadie
1.2         cat
1.3         camel
1.3.2       camel2
1.3.11      camel11
</code></pre>

<p>I tried TreeMap but it sorts each character number. what will be used instead there if there is required to sort whole number inside String. I  want something like that as mentioned above in expected output.</p>

<pre><code>TreeMap&lt;String, String&gt; data = new TreeMap&lt;String, String&gt;();       
data.put("1",   "animal");
data.put("1.1", "dog");
data.put("1.2", "cat");     
data.put("1.3", "camel");

data.put("1.3.2", "camel2");
data.put("1.3.11", "camel11");

data.put("1.1.1", "tommy");
data.put("1.1.2", "Lily");
data.put("1.1.10", "Sadie");


SortedSet&lt;String&gt; keys = new TreeSet&lt;String&gt;(data.keySet());

System.out.println("Key         Value");

for(String key: keys){
    System.out.println(key+"        "+data.get(key));
</code></pre>

<p>Actual Output</p>

<pre><code> Key        Value
1       animal
1.1         dog
1.1.1       tommy
1.1.10      Sadie
1.1.2       Lily
1.2         cat
1.3         camel
1.3.11      camel11
1.3.2       camel2
</code></pre>