title: Complexity of Set operations
body: <p>This is what I am doing:<br>
  String one = "some string"<br>
  String two = "some string"  </p>
  
  <p>I want to know all the characters that are in string <strong>one</strong> and <strong>two</strong> and they should come in order as they are in string one  </p>
  
  <p>I wrote a Java program which by using Collections performs set operations on both the collection.<br>
  What I would like to know that what is the complexity of performing set operations, is it polynomial time or linear time  </p>
  
  <p>My program is here  </p>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  
  package careercup.google;
  
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Iterator;
  import java.util.List;
  
  /**
   *
   * @author learner
   */
  public class CharaterStringsIntersection {
      private static final String one = "abcdefgabcfmnx";
      private static final String two = "xbcg";
  
      public static void main(String args[]){
          List&lt;Character&gt; l_one = new ArrayList&lt;Character&gt;();
          List&lt;Character&gt; l_two = new ArrayList&lt;Character&gt;();
  
          for(int i=0; i&lt;one.length(); i++){
             l_one.add(one.charAt(i));
          }
          for(int j=0; j&lt;two.length(); j++){
              l_two.add(two.charAt(j));
          }
  
          l_one.retainAll(l_two);
  
          Iterator iter = l_one.iterator();
          while(iter.hasNext()){
              System.out.println(" &gt; " + iter.next());
          }
      }
  }
  </code></pre>
  
  <p>Output :</p>
  
  <pre><code>run:
   &gt; b
   &gt; c
   &gt; g
   &gt; b
   &gt; c
   &gt; x
  </code></pre>