会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132665个问题
JAVA 全系列/第二阶段:JAVA 基础深化和提高/多线程和并发编程(旧) 38236楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/多线程和并发编程(旧) 38237楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 38238楼
JAVA 全系列/第三阶段:数据库编程/JDBC技术(旧) 38239楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/反射技术(旧) 38243楼
JAVA 全系列/第一阶段:JAVA 快速入门/数组和数据存储 38249楼

    public boolean regionMatches(boolean ignoreCase, int toffset,
            String other, int ooffset, int len) {
        char ta[] = value;
        int to = toffset;
        char pa[] = other.value;
        int po = ooffset;
        // Note: toffset, ooffset, or len might be near -1>>>1.
        if ((ooffset < 0) || (toffset < 0)
                || (toffset > (long)value.length - len)
                || (ooffset > (long)other.value.length - len)) {
            return false;
        }
        while (len-- > 0) {
            char c1 = ta[to++];
            char c2 = pa[po++];
            if (c1 == c2) {
                continue;
            }
            if (ignoreCase) {
                // If characters don't match but case may be ignored,
                // try converting both characters to uppercase.
                // If the results match, then the comparison scan should
                // continue.
                char u1 = Character.toUpperCase(c1);
                char u2 = Character.toUpperCase(c2);
                if (u1 == u2) {
                    continue;
                }
                // Unfortunately, conversion to uppercase does not work properly
                // for the Georgian alphabet, which has strange rules about case
                // conversion.  So we need to make one last check before
                // exiting.
                if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
                    continue;
                }
            }
            return false;
        }
        return true;
    }

老师?String源码中的这一段

    public boolean regionMatches(boolean ignoreCase, int toffset,
            String other, int ooffset, int len) {
        char ta[] = value;
        int to = toffset;
        char pa[] = other.value;
        int po = ooffset;

为什么不直接使用传进来的形参,而是再声明另外的变量,赋值。

再操作新声明的变量。

为什么绕這莫一大圈呢?

JAVA 全系列/第二阶段:JAVA 基础深化和提高/常用类 38250楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637