Creation of a map from another map in Java
<p>I have to convert a Map- Map1 into Map2.</p>

<p>Map1:</p>

<pre><code>A.B.Key    = "Key"
A.B.Value  = "Value"
A.B.Key1   = "Key1"
A.B.Value1 = "Value1"
A.B.Key2   = "Key2"
A.B.Value2 = "Value2"
</code></pre>

<p>Map2:</p>

<pre><code>Key  = Value
Key1 = Value1
Key2 = Value2
</code></pre>

<p>Map1 is created from this XML file:</p>

<p>XML File:</p>

<pre><code>&lt;A&gt;
  &lt;B&gt;
    &lt;Key&gt; Key &lt;/Key&gt;
    &lt;Value&gt; Value &lt;/Value&gt;
  &lt;/B&gt;
  &lt;B&gt;
    &lt;Key&gt; Key1 &lt;/Key&gt;
    &lt;Value&gt; Value1 &lt;/Value&gt;
  &lt;/B&gt;
  &lt;B&gt;
    &lt;Key&gt; Key2 &lt;/Key&gt;
    &lt;Value&gt; Value2 &lt;/Value2&gt;
  &lt;/B&gt;
&lt;/A&gt;
</code></pre>

<p>I am getting the problem because Map1 contents are not in the order, in which Its mentioned in the XML file. Map1 is something like this:</p>

<p>Actual Map1:</p>

<pre><code>A.B.Key2   = "Key2"
A.B.Key    = "Key"
A.B.Value  = "Value"
A.B.Value1 = "Value1"
A.B.Value3 = "Value2"
A.B.Key1   = "Key1"
</code></pre>

<p>Where am I going wrong?</p>
