GitHub

https://github.com/Choidongjun0830

Java

[Java] Anagram Checker

gogi masidda 2023. 8. 13. 13:22
import java.util.Arrays;

public class StringMagic {

    public boolean areAnagrams(String str1, String str2) {
        if(str1 == null || str2 == null){
            return false;
        }else if(str1.length() != str2.length()){
            return false;
        }
        
        str1 = str1.toLowerCase();
        str2 = str2.toLowerCase();
        
        char[] charArray1 = str1.toCharArray();
        char[] charArray2 = str2.toCharArray();
        
        Arrays.sort(charArray1);
        Arrays.sort(charArray2);
        
        return Arrays.equals(charArray1,charArray2);
    }
}
728x90