src/main/java/me/codeboy/common/base/util/CBStringUtil.java
public static int compare(String str1, String str2) {
        //有一个为null的话按照非null的大处理
        if (str1 == null || str2 == null) {
            return Integer.compare((str1 == null) ? 0 : 1, (str2 == null) ? 0 : 1);
        }

        if (str1.length() == 0 || str2.length() == 0) {
            return str1.length() - str2.length();
        }

        int res = 0;
        int position = 0;
        int maxComparePosition = Math.min(str1.length(), str2.length());
        while (position < maxComparePosition) {
            char ch1 = str1.charAt(position);
            char ch2 = str2.charAt(position);
            if (ch1 == ch2) {
                position++;
                continue;
            }

            //不相等的话返回差值,代表字符串大小
            res = ch1 - ch2;
            break;
        }

        //如果最后比较结果是相等的话,说明比较长度内的字符串相等,需要比较字符串长度
        return res == 0 ? (str1.length() - str2.length()) : res;
    }
public static int compare(String str1, String str2) {
        //有一个为null的话按照非null的大处理
        if (str1 == null || str2 == null) {
            return Integer.compare((str1 == null) ? 0 : 1, (str2 == null) ? 0 : 1);
        }

        if (str1.length() == 0 || str2.length() == 0) {
            return str1.length() - str2.length();
        }

        int res = 0;
        int position = 0;
        int maxComparePosition = Math.min(str1.length(), str2.length());
        while (position < maxComparePosition) {
            char ch1 = str1.charAt(position);
            char ch2 = str2.charAt(position);
            if (ch1 == ch2) {
                position++;
                continue;
            }

            //不相等的话返回差值,代表字符串大小
            res = ch1 - ch2;
            break;
        }

        //如果最后比较结果是相等的话,说明比较长度内的字符串相等,需要比较字符串长度
        return res == 0 ? (str1.length() - str2.length()) : res;
    }
按照ascii(字典)顺序比较字符大小

@param str1 字符串1
@param str2 字符串2
@return 0-相等 正数-大于 负数-小于