title: How to compare two huge List<String> in Java?
body: <p>My application generates 2 big lists (up to 3.5mill string records). I need the best and fastest way to compare it. Currently I am doing it like this:</p>
  
  <pre><code>List list1 = ListUtils.subtract(sourceDbResults, hiveResults);
  List list2 = ListUtils.subtract(hiveResults, sourceDbResults);
  </code></pre>
  
  <p>But this method is really expensive on memory as i see from jconsole and sometimes process even stack on it. Any good solutions or ideas?</p>
  
  <p>Element positions/order in the list are always the same, so I dont need to deal with it. After comparing I need to know if the list are the same and to get the differences from these list if they are not the same. Subtract works perfect for small lists.</p>