title: Compare two lists of different sObjects without double loops in Apex
body: <p>I need to check a list of custom objects (instance), to find matches in another list of custom objects (template). A match is where the fields contain the same values, or value is null on the template. The existing code has a double loop like:</p>
  
  <pre><code>for(instance theInstance : theInstanceList){
      for(template thTemplate: theTemplateList){
          if((theInstanve.field1 = theTemplate.field1 || theTemplate.field1 == null) &amp;&amp;{
             (theInstanve.field2 = theTemplate.field2 || theTemplate.field2 == null) &amp;&amp;{
              and so on for 8-10 fields ....{
             ){
                  Carry out requirements ........{
             }
       }
  }
  </code></pre>
  
  <p>It's pretty inefficient when there are lots of records. Any thoughts on a nicer solution?</p>