Android: Compare two Maps keys, if keys are equal create new object
<p>I have two <code>LinkedHashMap&lt;String, MyType&gt;</code> where keys can be common (say key from first map can be "key" and key from second map can be also "key". I need to compare this two maps and when keys are equal I want create new object where <code>firsMapEntry.getValue()</code> <code>secondMapEntry.getValue()</code> are attributes of new object [ <code>new MyObject(firsMapEntry.getValue(), secondMapEntry.getValue())</code> ]. Maps are in <code>Collection</code> so I iterate through collections. </p>

<p>Here's my source:</p>

<pre><code>firstIterator = firsCollection.iterator();
secondIterator = secondCollection.iterator();

    while (firstIterator.hasNext() &amp;&amp; secondIterator.hasNext()) {
        Map&lt;String, MyType1&gt; firsMap = firstIterator.next();
        Map&lt;String, List&lt;MyType2&gt;&gt; secondMap = secondIterator
                .next();

        firstMapIterator = firstMap.entrySet().iterator();
        secondMapIterator = secondMap.entrySet().iterator();

        while (firstMapIterator.hasNext() &amp;&amp; secondMapIterator.hasNext()) {
            Map.Entry&lt;String, MyType1&gt; firstEntry = ((Map.Entry&lt;String, MyType1&gt;) firstMapIterator.next());
            Map.Entry&lt;String, List&lt;MyType2&gt;&gt; secondEntry = ((Map.Entry&lt;String, List&lt;MyType2&gt;&gt;) secondMapIterator.next());


           // Here I was trying to compare keys but unsuccessfuly

          // if keys are equal create new object

        My Object object = new MyObject(firsEntry.getValue(),
                    secondEntry.getValue());
                      Map&lt;String, MyObject&gt; map = new LinkedHashMap&lt;String,MyObject(); map.put("key", object);

        }
    }
</code></pre>

<p>Return type of method is <code>List&lt;Map&lt;String, MyObject&gt;&gt;</code>.
I don't know if my method is effecient, but how to compare two keys and create new object from values. Every help will be appreciated. Thank you.</p>
