HTML & JS
/*package whatever //do not write package name here */

import java.io.*;

class GFG {
    public static boolean checkAnagram(String a, String b)
    {
        int[] arr = new int[26];
        for(int i = 0;i<a.length();i++)
        {
            arr[a.charAt(i) - 'a']++;
        }
        
        for(int i = 0;i<b.length();i++)
        {
            arr[b.charAt(i) - 'a']--;
        }
        for(int i = 0;i<arr.length;i++)
        {
            if(arr[i]!=0)
            return false;
        }
        return true;
    }
	public static void main (String[] args) {
	System.out.println(checkAnagram("tocdode","cotode"));
	System.out.println(checkAnagram("tocode","cotode"));
	System.out.println(checkAnagram("decdode","cotode"));
	System.out.println(checkAnagram("tocdode","tocdode"));
	}
}

Generated URL:

Output:

false
true
false
true
Report Bug