Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Java reference

String.equalsIgnoreCase()

Compares two strings ignoring letter case.

Available since: Java 1.0

Syntax

public boolean equalsIgnoreCase(String anotherString)

Parameters

ParameterTypeDescription
anotherStringStringThe string to compare with. For null the result is false.

Return value

booleantrue if the strings are equal ignoring case.

Examples

A user answer in any case:

void main() {
    String answer = "YES";
    IO.println(answer.equalsIgnoreCase("yes"));
    IO.println(answer.equals("yes"));
}

Output:

true
false

Notes

For case-insensitive sorting there is compareToIgnoreCase() and the ready comparator String.CASE_INSENSITIVE_ORDER.

See also

Related recipes

In the tutorial

  • String methods — The main String methods in Java: searching, substring, changing case, strip, replace, split, join, repeat and string checks.

Thanks for reading!

Donate to the site — we work hard for you.