java tutorial - Java Strings compareToIgnoreCase() method - java programming - learn java - java basics - java for beginners
![java strings copy value of](https://wikitechy.com/tutorials/java/img/java-images/java-strings-compare-to-ignore-case.gif)
Learn java - java tutorial - java strings compare to ignore case - java examples - java programs
Description
Java - The compareToIgnoreCase () method — in Java, compares lexically two lines, ignoring the case of letters.
Syntax
The syntax of the method is:
int compareToIgnoreCase(String str)
click below button to copy the code. By - java tutorial - team
Options
Detailed information about the parameters:
- str is a string for comparison.
Return value
- In Java, compareToIgnoreCase () returns a negative integer, zero, or a positive integer if the specified string is less, equal to or greater than the compared string, ignoring the case.
Sample Code
public class Test {
public static void main(String args[]) {
String str1 = "Welcome to Wikitechy Website!";
String str2 = "Welcome to Wikitechy!";
String str3 = "Hi,welcome to wikitechy!";
int result = str1.compareToIgnoreCase(str2);
System.out.println(result);
result = str2.compareToIgnoreCase(str3);
System.out.println(result);
result = str3.compareToIgnoreCase(str1);
System.out.println(result);
}
}
click below button to copy the code. By - java tutorial - team
Output :
-1
15
-15