String.equalsIgnoreCase()
Compares two strings ignoring letter case.
Available since: Java 1.0
Syntax
public boolean equalsIgnoreCase(String anotherString)Parameters
| Parameter | Type | Description |
|---|---|---|
| anotherString | String | The 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
falseNotes
For case-insensitive sorting there is compareToIgnoreCase() and the ready comparator String.CASE_INSENSITIVE_ORDER.
See also
- String.equals() — Compares the contents of two strings.
- String.toLowerCase() — Returns a copy of the string with all letters in lower case.
- String.compareTo() — Compares two strings in dictionary (lexicographic) order.
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.