Created
February 27, 2019 22:57
-
-
Save mali30/044c42a7b41bc580e6b0fc5bbbc6d51d to your computer and use it in GitHub Desktop.
Method to validate if two strings are anagrams
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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