title: What is the fastest way to compare two sets in Java?
body: <p>I am trying to optimize a piece of code which compares elements of list.</p>
  
  <p>Eg.</p>
  
  <pre><code>public void compare(Set&lt;Record&gt; firstSet, Set&lt;Record&gt; secondSet){
      for(Record firstRecord : firstSet){
          for(Record secondRecord : secondSet){
              // comparing logic
          }
      }
  }
  </code></pre>
  
  <p>Please take into account that the number of records in sets will be high.</p>
  
  <p>Thanks</p>
  
  <p>Shekhar</p>