title: How to check if two words are anagrams
body: <p>I have a program that shows you whether two words are anagrams of one another. There are a few examples that will not work properly and I would appreciate any help, although if it were not advanced that would be great, as I am a 1st year programmer. &quot;schoolmaster&quot; and &quot;theclassroom&quot; are anagrams of one another, however when I change &quot;theclassroom&quot; to &quot;theclafsroom&quot; it still says they are anagrams, what am I doing wrong?</p>
  <pre class="lang-java prettyprint-override"><code>import java.util.ArrayList;
  public class AnagramCheck {
      public static void main(String args[]) {
          String phrase1 = &quot;tbeclassroom&quot;;
          phrase1 = (phrase1.toLowerCase()).trim();
          char[] phrase1Arr = phrase1.toCharArray();
  
          String phrase2 = &quot;schoolmaster&quot;;
          phrase2 = (phrase2.toLowerCase()).trim();
          ArrayList&lt;Character&gt; phrase2ArrList = convertStringToArraylist(phrase2);
  
          if (phrase1.length() != phrase2.length()) {
              System.out.print(&quot;There is no anagram present.&quot;);
          } else {
              boolean isFound = true;
              for (int i = 0; i &lt; phrase1Arr.length; i++) {
                  for (int j = 0; j &lt; phrase2ArrList.size(); j++) {
                      if (phrase1Arr[i] == phrase2ArrList.get(j)) {
                          System.out.print(&quot;There is a common element.\n&quot;);
                          isFound =;
                          phrase2ArrList.remove(j);
                      }
                  }
                  if (isFound == false) {
                      System.out.print(&quot;There are no anagrams present.&quot;);
                      return;
                  }
              }
              System.out.printf(&quot;%s is an anagram of %s&quot;, phrase1, phrase2);
          }
      }
  
      public static ArrayList&lt;Character&gt; convertStringToArraylist(String str) {
          ArrayList&lt;Character&gt; charList = new ArrayList&lt;Character&gt;();
          for (int i = 0; i &lt; str.length(); i++) {
              charList.add(str.charAt(i));
          }
          return charList;
      }
  }
  </code></pre>