Skip to content

Instantly share code, notes, and snippets.

@mali30
Created February 27, 2019 22:57
Show Gist options
  • Save mali30/044c42a7b41bc580e6b0fc5bbbc6d51d to your computer and use it in GitHub Desktop.
Save mali30/044c42a7b41bc580e6b0fc5bbbc6d51d to your computer and use it in GitHub Desktop.
Method to validate if two strings are anagrams
public static boolean isAnagaram(String a, String b){
char [] to_char = a.toCharArray();
char [] to_char2 = b.toCharArray();
int l1 = a.length();
int l2 = b.length();
Arrays.sort(l1);
Arrays.sort(l2);
if(l1 != l2){
return false;
}
for(int i =0; i < to_char.length; i++){
if(to_char[i] != to_char2){
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment