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

Introducing Java equalsIgnoreCase() method examples

零下一度
Release: 2017-05-23 10:52:44
Original
2171 people have browsed it

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

Syntax

public boolean equalsIgnoreCase(String anotherString)
Copy after login

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 );
}}
Copy after login

The execution result of the above program is:

返回值 = true
返回值 = false
返回值 = true
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template