在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java  Python  網(wǎng)絡(luò)安全/ StringUtils中equals()和equalsIgnoreCase()源

StringUtils中equals()和equalsIgnoreCase()源碼中是怎么實(shí)現(xiàn)忽略大小寫比較?

1、在使用org.apache.commons.lang3.StringUtils工具類的時(shí)候,查看了一下equals和equalsIgnoreCase兩個(gè)方法的源碼,想看一下是怎么實(shí)現(xiàn)忽略大小寫比較的,但是發(fā)現(xiàn),兩個(gè)方法比較的內(nèi)容基本是一樣的,有哪位能講解一下,兩個(gè)方法中源碼有什么本質(zhì)上的區(qū)別嗎?
2、我用的jar包是:commons-lang3-3.6.jar,兩個(gè)方法的源碼如下所示:

    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;
        }
    }
回答
編輯回答
壞脾滊

regionMatches(final CharSequence cs, final boolean ignoreCase, final int thisStart,

        final CharSequence substring, final int start, final int length)方法的第二個(gè)參數(shù)表示是否區(qū)不分大小寫, equals方法傳入的是false,equalsIgnoreCase傳入的是true.
2017年10月8日 05:14