title: Getting the common character count between two strings
body: <blockquote>
    <p>Given two strings, find the number of common characters between them.</p>
    
    <p>Example</p>
    
    <p>For s1 = "aabcc" and s2 = "adcaa", the output should be
    commonCharacterCount(s1, s2) = 3.</p>
    
    <p>Strings have 3 common characters - 2 "a"s and 1 "c".</p>
  </blockquote>
  
  <p>I've been stuck on this problem for quite a bit and I've tried many approaches to solving this problem, but I cannot quite figure it out. I have the principal idea of how to solve it, but I cannot transfer that to code.</p>
  
  <p>What my approach is to put the string's characters in their own ArrayList and use nested loops to iterate through them comparing the similar characters and storing the count in a int value. I don't have any code because I have tried many different attempts varying my code, but no luck.</p>
  
  <p>I used two nested for loops that are separate from each other like this:</p>
  
  <pre><code>for(int i = 0; i&lt;firstString.size(); i++){
      for(int j = 0; j&lt;secondString.size(); j++){
          if(firstString.get(i) == secondString.get(j){
              lettersInCommon++;
              secondString.remove(j);
              }
          }
  }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>for(int i = 0; i&lt;secondString.size(); i++){
      for(int j = 0; j&lt;firstString.size(); j++){
          if(firstString.get(i) == secondString.get(j){
              lettersInCommon2++;
              firstString.remove(i);
              }
          }
  }
  </code></pre>
  
  <p>So after these loops run, I return the difference between the two lettersinCommon ints depending on their size to avoid negatives. So if lettersInCommon > lettersInCommon2 -- return lettersInCommon - lettersInCommon2; and vice versa.</p>
  
  <p>I don't want anyone to tell me how to code this, I would only like advice towards my logic to see if I can simplify this problem or if I am missing something.</p>
  
  <p>I would also like to state that this code works for some test cases but not all.</p>
  
  <p>I've been taking into account the comments I've received and gotten this far:</p>
  
  <pre><code>ArrayList&lt;Character&gt; firstString = new ArrayList&lt;Character&gt;();
  ArrayList&lt;Character&gt; secondString = new ArrayList&lt;Character&gt;();
  int lettersInCommon = 0;
  
  for(int i = 0; i&lt;s1.length(); i++){
      firstString.add(s1.charAt(i));
  }
  
  for(int i = 0; i&lt;s2.length(); i++){
      secondString.add(s2.charAt(i));
  }
  Collections.sort(firstString);
  Collections.sort(secondString);
  for(char c : firstString){
      if(firstString.contains(c) &amp;&amp; secondString.contains(c)){
          lettersInCommon++;
          secondString.remove(s2.indexOf(c));
      }
  }
  </code></pre>
  
  <p>I am really close, but the error I get is an out of bounds exception on this line
  <code>secondString.remove(s2.indexOf(c));</code> </p>
  
  <p>Does anyone have any insight on this?</p>