Home > Java > javaTutorial > What does equalsignorecase mean in java

What does equalsignorecase mean in java

下次还敢
Release: 2024-05-09 06:39:16
Original
882 people have browsed it

The equalsIgnoreCase() method in Java is used to compare two strings, ignoring case. The usage is as follows: accepts a string parameter. Returns true if the two strings are equal (ignoring case); otherwise returns false. Case comparison uses the rules of the current locale. Throws an exception if any parameter is null.

What does equalsignorecase mean in java

equalsIgnoreCase in Java

In Java, the equalsIgnoreCase() method is used to compare two strings, Case is ignored.

Usage

This method accepts a string parameter and returns a Boolean value:

  • If the two strings are equal (ignored uppercase and lowercase), returns true.
  • If the two strings are not equal, return false.

Grammar

<code class="java">public boolean equalsIgnoreCase(String str)</code>
Copy after login

Description

  • Case comparison is performed using the rules of the current locale of.
  • If any parameter is null, a NullPointerException is thrown.
  • This method is similar to the equals() method, except that it ignores case.

Example

<code class="java">String str1 = "Hello";
String str2 = "hello";

// 忽略大小写比较
boolean result = str1.equalsIgnoreCase(str2);

// 打印结果
System.out.println(result); // 输出 true</code>
Copy after login

Applicable scenarios

equalsIgnoreCase() method is usually used in the following scenarios:

  • Compare case-insensitive strings such as usernames or passwords.
  • Find words or phrases that are not case sensitive.
  • Handle input from different sources, which may use different casing conventions.

The above is the detailed content of What does equalsignorecase mean in java. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template