Compare with equalsIgnoreCase()
Write a Java function that takes two strings and returns true if they are equal ignoring case using equalsIgnoreCase(). This method compares strings lexicographically without considering case differences.
String.equalsIgnoreCase() is a method that compares two strings for equality, ignoring case considerations. It returns true if the strings have the same length and corresponding characters are equal ignoring case. The method is case-insensitive for both uppercase and lowercase letters in the Latin alphabet.
Unlike equals() which compares strings with case sensitivity (e.g., "Hello" != "hello"), equalsIgnoreCase() treats uppercase and lowercase as equivalent. This is useful for user input validation, command parsing, and any scenario where case-insensitive comparison is needed.
Time complexity is O(n) where n is the string length. Space complexity is O(1). The method does not create new strings; it compares characters directly using Character.toLowerCase() and Character.toUpperCase() for each character pair.
Edge cases include empty strings (equal), null strings (throws NullPointerException if called on null, returns false if passed as argument), strings with different lengths (returns false without character comparison), and strings with Unicode characters beyond ASCII.
Example Input & Output
Case-insensitive equal
Both empty
Different case but equal
Single char different case
Different strings
Algorithm Flow

Solution Approach
Best Answers
class Solution {
public boolean solution(String a, String b) {
return a.equalsIgnoreCase(b);
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
