4.67 参考/equalsIgnoreCase 方法

String equalsIgnoreCase 方法

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

语法

public boolean equalsIgnoreCase(String anotherString)

参数

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

返回值

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

实例

public class Test {
    public static void main(String args[]) {
        String Str1 = new String("nowcoder");
        String Str2 = Str1;
        String Str3 = new String("nowcoder");
        String Str4 = new String("NOWCODER");
        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
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务