equalsIgnoreCase() 方法用于将字符串与指定的对象比较,不考虑大小写。

实例

equals() 会判断大小写区别,equalsIgnoreCase() 不会判断大小写区别:

public class Test {
    public static void main(String args[]) {
        String s1= new String("today");
        String s2= s1;
        String s3= new String("today");
        String s4= new String("TODAY");
        boolean retVal;

        str = s1.equals( s2);
        System.out.println("返回值 = " + str);

        str = s3.equals( s4);
        System.out.println("返回值 = " + str );

        str  = s1.equalsIgnoreCase( s4);
        System.out.println("返回值 = " + str );
    }
}

以上程序执行结果为:

返回值 = true
返回值 = false
返回值 = true

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐