账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    StringUtils中equals()和equalsIgnoreCase()源码中是怎么实现忽略大小写比较?
    70
    0

    1、在使用org.apache.commons.lang3.StringUtils工具类的时候,查看了一下equals和equalsIgnoreCase两个方法的源码,想看一下是怎么实现忽略大小写比较的,但是发现,两个方法比较的内容基本是一样的,有哪位能讲解一下,两个方法中源码有什么本质上的区别吗?
    2、我用的jar包是:commons-lang3-3.6.jar,两个方法的源码如下所示:

        public static boolean equals(CharSequence cs1, CharSequence cs2) {
            if (cs1 == cs2) {
                return true;
            } else if (cs1 != null && cs2 != null) {
                if (cs1.length() != cs2.length()) {
                    return false;
                } else {
                    return cs1 instanceof String && cs2 instanceof String ? cs1.equals(cs2) : CharSequenceUtils.regionMatches(cs1, false, 0, cs2, 0, cs1.length());
                }
            } else {
                return false;
            }
        }
        public static boolean equalsIgnoreCase(CharSequence str1, CharSequence str2) {
            if (str1 != null && str2 != null) {
                if (str1 == str2) {
                    return true;
                } else {
                    return str1.length() != str2.length() ? false : CharSequenceUtils.regionMatches(str1, true, 0, str2, 0, str1.length());
                }
            } else {
                return str1 == str2;
            }
        }
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 圈ぐ心ㄅ 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部