会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132358个问题

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

提问:在视频代码中,for循环输出i,通过判断c1.get(Calendar.DAY_OF_MONTH)是否等于7(周六)来输出回车换行什么意义?c1.get(Calendar.DAY_OF_MONTH)只跟输入的日期有关啊,这个值并不会改变啊,在for循环中这个值是固定的,且在这个视频中,这个值为6,并不等于7,为什么回车换行了呢?

package cn.sxt.test;

import java.text.DateFormat;
import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Scanner;

public class TestGregorianCalendar {

	public static void main(String[] args) throws ParseException {
		// TODO Auto-generated method stub
		Calendar cal = new GregorianCalendar();
		System.out.println("please input a date:yyyy-MM-dd");
		Scanner scan = new Scanner(System.in);
		String str=scan.nextLine();
		DateFormat d =new SimpleDateFormat("yyyy-MM-dd");
		Date d2 = d.parse(str);
		cal.setTime(d2);
		cal.set(Calendar.DAY_OF_MONTH, 1); //It's very important
		int dayOfWeek=cal.get(Calendar.DAY_OF_WEEK);
		System.out.println(cal.get(7));
		System.out.println(dayOfWeek);
		System.out.println("Sun\tMon\tTue\tWed\tThu\tFri\tSat");
		for (int i = 1; i < dayOfWeek; i++) {
			System.out.print("\t");
		}
		for (int i = 1; i <=31; i++) {
			System.out.print(i+"\t");
			if (cal.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY) {//难不成cal.get(Calendar.DAY_OF_WEEK)的值
			会随着循环变化?我的代码这里的值并没有变化啊
				System.out.println();
			}
		}
		cal.add(Calendar.DAY_OF_MONTH, 1);
	}

}


JAVA 全系列/第二阶段:JAVA 基础深化和提高/常用类 3890楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/多线程技术(旧) 3891楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/手写服务器项目(旧) 3892楼

import java.util.ArrayList;

public class Tset {
	public static void main(String []args) {
		//创建集合对象,同时明确了集合中所存储的对象类型只能是Person 类型
		ArrayList<Person> al=new ArrayList<Person>();
		//创建Person类型对象添加到集合中
		Person p1=new Person("marry",20);
		Person p2=new Person("lili",29);
		Person p3=new Person("jack",18);
		al.add(p1);
		al.add(p2);
		al.add(p3);
		//遍历集合
		print(al);
		
		//创建集合用于存储student类型的对象
		ArrayList<Student> al2=new ArrayList<Student>();
		Student stu1=new Student("sean",20,"sxt1001");
		Student stu2=new Student("nico",19,"sxt1002");
		//添加到集合
		al2.add(stu1);
		al2.add(stu2);
		//遍历集合
		print(al2);
		System.out.println("************");
		//调用show()方法
		show(al);
		show(al2);
		ArrayList<Object> alobject=new ArrayList<Object>();
		Object ob1=new Object();
		Object ob2=new Object();
		alobject.add(ob1);
		alobject.add(ob2);
		show(alobject);
	}
	//person以及person子类可以使用
	public static void print(ArrayList<? extends Person> al) {//相当于ArrayList<Person> al=new ArrayList<Student>();不匹配
		for(Person p:al) {
			System.out.println(p);
		}
	}
	public static void show(ArrayList<? super Student> al) {
		for(Object obj:al) {
			System.out.println(obj);
		}
	}
}
public static void show(ArrayList<? super Student> al) {
		for(Object obj:al) {
			System.out.println(obj);
		}
	}

为什么不是下面这个呢?

for(Student stu:al) {
			System.out.println(stu);
		}


JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 3895楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/XML 技术(旧) 3898楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/XML 技术(旧) 3899楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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