I have written this code and I am wondering if the code could be optimised.Please review. public class Anagram1{   public static boolean check(char[] c1,char[] c2,int l1,int l2){     /*if the lengths of the strings are not equal,they cannot be anagrams of each other */    if(l1!=l2){        return false;    }    int count = 0;    //nested for loops to compare the characters of both strings.    //if the characters match,then the strings are anagrams of each other.    for(int i=0; i<l1; i++){        for(int j=0; j<l2; j++){            if(c1[i]==c2[j]){                count++;                break;      //break used so as to count only a single occurrence of a            }               //character.        }    }    if(count==l1 && count==l2){        return true;    }    return false;}public static void main(String[] args) {    String s1 = abcd;    String s2 = acdb;    char[] c1 = s1.toCharArray();    char[] c2 = s2.toCharArray();    int l1 = s1.length();    int l2 = s2.length();    System.out.println(check(c1,c2,l1,l2));  }}
Program to check whether two strings are anagrams of each other
java;beginner;strings
So I have rewritten the code all over again with a slightly different logic.Please review.public class Anagram{  public static boolean check(char[] c1,char[] c2,int l1,int l2){        /*If the lengths are unequal,return false.*/        if(l1!=l2){            return false;        }        int[] count1 = new int[256];        int[] count2 = new int[256];        for(int i=0; i<l1; i++){            count1[c1[i]]++;        }        for(int j=0; j<l2; j++){            count2[c2[j]]++;        }        /*Comparing both the count arrays.*/        for(int k=0; k<count1.length; k++){            if(count1[k]!=count2[k]){                return false;             }        }        return true;}  public static void main(String[] args) {    String s1 = anagram;    String s2 = nagarnm;    char[] ch1 = s1.toCharArray();    char[] ch2 = s2.toCharArray();    int len1 = s1.length();    int len2 = s2.length();   System.out.println(check(ch1,ch2,len1,len2));    } }