Home  >  Article  >  Java  >  Introducing Java equalsIgnoreCase() method examples

Introducing Java equalsIgnoreCase() method examples

零下一度
零下一度Original
2017-05-23 10:52:442120browse

equalsIgnoreCase() method is used to compare a string with the specified object, regardless of case.

Syntax

public boolean equalsIgnoreCase(String anotherString)

Parameters

anObject -- with characters String objects to compare against.

Return value

Returns true if the given object is equal to the string; otherwise returns false.

Example

public class Test {
public static void main(String args[]) {
String Str1 = new String("runoob");
String Str2 = Str1;
String Str3 = new String("runoob");
String Str4 = new String("RUNOOB");
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 );
}}

The execution result of the above program is:

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

[Related recommendations]

1. Detailed explanation of Java The difference between equals(), equalsIgnoreCase() and ==

2. Share the difference between equals and equalsignorecase in Java and their usage example tutorial

3 . Image and text examples of equalsIgnoreCase method in java

The above is the detailed content of Introducing Java equalsIgnoreCase() method examples. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn