String comparison in java is used to compare two different lines. We can compare a string regardless of the case (upper case / lower case). Consider str1 = "HELLO WORLD"; str2 = "hello world"; If we want to compare them with strings, there are two ways: String compareTo (String). String compareToIgnoreCase (String). String comparison: str1 compareTo (str2); This statement will return false as the result, because java is a case-sensitive language. You can also compare a string, regardless of their case, using the instruction: str1 compareToIgnoreCase (str2); This will lead to true output, because it will only check the character that is stored in str1 and str2 without worrying about the case.
source share