title: How to rearrange the items in a map based on another map keys
body: <p>Hi I had a requirement where objects of a map are to arranged
  in order of keys of another map.
  here is the map</p>
  
  <pre><code>Map ObjectMap = new HashMap()
  ObjectMap .put(id1,Obj1);
  ObjectMap .put(id2,Obj2);
  ObjectMap .put(id3,Obj3);
  ObjectMap .put(id4,Obj4);
  </code></pre>
  
  <p>Now a rank map decides the order of ids in ObjectMap </p>
  
  <pre><code>Map rankedMap = new HashMap()
  
  rankedMap .put(rank1,id3);
  rankedMap .put(rank2,id4);
  rankedMap .put(rank3,id1);
  rankedMap .put(rank4,id2);
  </code></pre>
  
  <p>Now I have to arrange the ObjectMap objects accoding to the rank of each ids like</p>
  
  <pre><code>ObjectMap .put(id3,Obj1);
  ObjectMap .put(id4,Obj2);
  ObjectMap .put(id1,Obj3);
  ObjectMap .put(id2,Obj4);
  </code></pre>
  
  <p><code>ids</code> are <code>Long</code> objects</p>
  
  <p><code>ranks</code> are <code>int</code> objects</p>
  
  <p>Please help Thanks in advance</p>