美文网首页
判断两字符串相等java

判断两字符串相等java

作者: whiteList | 来源:发表于2017-07-01 11:48 被阅读0次
        //同一对象
        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

          本文链接:https://www.haomeiwen.com/subject/ibbwcxtx.html