title: are two anagram or not?
body: <p>My question is that in this code, initially we have taken boolean <strong>isAnagram</strong> false, and then set the condition, but we are getting wrong result. As it is clearly understood that they are not anagram but code output is 'anagram' .</p>
  <pre><code>package strings;
  
  public class Anagrams {
  
      public static void main(String[] args) {
          
          String a = &quot;aab&quot;;
          String b = &quot;abc&quot;;
          
          boolean isAnagram = false;
          
          int al[] = new int[256];
          int bl[] = new int[256];
          
          for(char c:a.toCharArray()) {
              int index = (int)c;
              al[index]++;
              }
          for(char c:b.toCharArray()) {
              int index = (int)c;
              bl[index]++;
              }
          
          for(int i = 0; i&lt;256; i++) {
              if(al[i] == bl[i]) {
                  isAnagram = true;
              }
          }
          
          if(isAnagram) {
              System.out.println(&quot;anagram&quot;);
          }else {
              System.out.println(&quot;not anagram&quot;);
          }
      
          }
      }
  }
  </code></pre>