title: Java Collection performance question
body: <p>I have created a method that takes two <code>Collection&lt;String&gt;</code> as input and copies one to the other. </p>
  
  <p>However, I am not sure if I should check if the collections contain the same elements before I start copying, or if I should just copy regardless. This is the method:</p>
  
  <pre><code> /**
    * Copies from one collection to the other. Does not allow empty string. 
    * Removes duplicates.
    * Clears the too Collection first
    * @param src
    * @param dest
    */
   public static void copyStringCollectionAndRemoveDuplicates(Collection&lt;String&gt; src, Collection&lt;String&gt; dest) {
    if(src == null || dest == null)
     return;
  
    //Is this faster to do? Or should I just comment this block out
    if(src.containsAll(dest))
     return;
  
    dest.clear();
    Set&lt;String&gt; uniqueSet = new LinkedHashSet&lt;String&gt;(src.size());
    for(String f : src) 
     if(!"".equals(f)) 
      uniqueSet.add(f);
  
    dest.addAll(uniqueSet);
   }
  </code></pre>
  
  <p>Maybe it is faster to just remove the </p>
  
  <pre><code>if(src.containsAll(dest))
      return;
  </code></pre>
  
  <p>Because this method will iterate over the entire collection anyways.</p>