会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132884个问题
JAVA 全系列/第二阶段:JAVA 基础深化和提高/常用类 2252楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/常用类 2254楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/异常机制 2255楼

    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 基础深化和提高/常用类 2256楼

老师,为啥运行了几次之后会出现先消费馒头啊/** * 消费者与生产者 */package com.company;/** * 定义一个馒头类 */class ManTou{ private int Id; public ManTou(int Id){ this.Id=Id; } public int getId() { return Id; }}/** * 定义缓冲区 */class SyncStack{ //定义存放盒子的馒头 private ManTou[] mt =new ManTou[10]; //定义操作盒子的索引 private int index; /** * 放馒头 */ public synchronized void push(ManTou manTou){ //判断盒子是否已满 while (this.index==this.mt.length) try { /** * 语法:wait();该方法必须要在synchronized块中调用。 * wait();执行后,会将持有的对象锁释放,并进入阻塞状态。 * 其他需要该对象锁的线程就可以继续运行了。 */ this.wait(); } catch (InterruptedException e) { e.printStackTrace(); } //唤醒取馒头的线程 /** * 语法:必须要在synchronized块中调用。 * 该方法会唤醒等待状态队列中的一个线程。 */ this.notify(); this.mt[this.index]=manTou; this.index++; } /** * 取馒头 * @return */ public synchronized ManTou pop(){ while (this.index==0){ try { /** * 语法:wait();该方法必须要在synchronized块中调用。 * wait();执行后,会将持有的对象锁释放,并进入阻塞状态。 * 其他需要该对象锁的线程就可以继续运行了。 */ this.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } /** * 语法:必须要在synchronized块中调用。 * 该方法会唤醒等待状态队列中的一个线程。 */ this.notify(); this.index--; return this.mt[this.index]; }}/** * 生产者线程 */class Shengchan extends Thread{ private SyncStack ss; public Shengchan(SyncStack ss){ this.ss=ss; } @Override public void run() { for (int i=0;i<10;i++){ System.out.println("生产馒头:"+i); ManTou manTou=new ManTou(i); this.ss.push(manTou); } }}/** * 消费者线程 */class xiaofei extends Thread{ private SyncStack ss; public xiaofei(SyncStack ss){ this.ss=ss; } @Override public void run() { for (int i=0;i<10;i++){ System.out.println("消费馒头:"+i); } }}public class ProduceThread { public static void main(String[] args) { SyncStack ss=new SyncStack(); new Shengchan(ss).start(); new xiaofei(ss).start(); }}

JAVA 全系列/第二阶段:JAVA 基础深化和提高/多线程技术(旧) 2257楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/IO 流技术(旧) 2258楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器 2261楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 2262楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/常用类 2263楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 2264楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 2265楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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