title: Comparing List of Map items in Java
body: <p>I have a function wherein i need to check if data matches in two lists.
  The list is a linkedlist of type <code>Map &lt;String, Object&gt;</code>.  How should I iterate to compare each item in map for both the list in the most efficient manner ?</p>
  
  <p>Right now I am trying to do something like this :</p>
  
  <pre><code>public boolean compare(List&lt;Map&lt;String, Object&gt;&gt; A,
              List&lt;Map&lt;String, Object&gt;&gt; B) {
          //Code for iteration 
          boolean result = false;
          if(A.size() == B.size()) {    
              int count = 0;
              for(Map&lt;String, Object&gt; a : A)
              {
                  for(Map&lt;String, Object&gt; b : B)
                  {
                      if (a.get('aID') == b.get('aID'))
                          count++;
                  }
              }
              if(count == A.size()) {
                  result = true;
              }
          }    
          else {
              //Data reconciliation failed :: Data size mismatch
          }
          return result;
      }
  </code></pre>
  
  <p>But this is an inefficient approach as each item in A is compared with every item in B. </p>
  
  <p>Is there a better approach ?</p>