判断两字符串相等java

    //同一对象
    if (s1 == s2) return true;
    if (s1 == null || s2 == null) return false;
    if (s1.length() == s2.length()) {
        int n = s1.length();
        int i = 0;
        char[] s1Arr = s1.toCharArray();
        char[] s2Arr = s2.toCharArray();
        while (i < n) {
            //忽略大小写
            if (Character.isLetter(s1Arr[i]) && Character.isLetter(s2Arr[i])) {
                s1Arr[i] = Character.toLowerCase(s1Arr[i]);
                s2Arr[i] = Character.toLowerCase(s2Arr[i]);
            }if (s1Arr[i] != s2Arr[i]) {
                return false;
            }
            i++;
        }
        return true;
    }
    return false;
}```

你可能感兴趣的:(判断两字符串相等java)