Java equalsIgnoreCase() 方法

Java 教程 · 2019-02-08 21:12:44

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

语法

public boolean equalsIgnoreCase(String anotherString)

参数

  • anObject -- 与字符串进行比较的对象。

返回值

如果给定对象与字符串相等,则返回 true;否则返回 false。

实例

public class Test {
    public static void main(String args[]) {
        String Str1 = new String("codercto");
        String Str2 = Str1;
        String Str3 = new String("codercto");
        String Str4 = new String("CODERCTO");
        boolean retVal;

        retVal = Str1.equals( Str2 );
        System.out.println("返回值 = " + retVal );

        retVal = Str3.equals( Str4);
        System.out.println("返回值 = " + retVal );

        retVal = Str1.equalsIgnoreCase( Str4 );
        System.out.println("返回值 = " + retVal );
    }
}

以上程序执行结果为:

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

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

About Face 2.0

About Face 2.0

Alan Cooper、Robert M. Reimann / Wiley / March 17, 2003 / USD 35.00

First published seven years ago-just before the World Wide Web exploded into dominance in the software world-About Face rapidly became a bestseller. While the ideas and principles in the original book......一起来看看 《About Face 2.0》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

MD5 加密
MD5 加密

MD5 加密工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具