11 May String compareToIgnoreCase() method in Java
The compareToIgnoreCase(String str) method in Java compares two strings lexicographically, ignoring case differences.
Syntax
Let us see the syntax,
1 2 3 |
int compareToIgnoreCase(String str) |
Parameters
Let us see the parameters,
- str – the comparison string
Example
The following is an example of compareToIgnoreCase(String str),
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
public class StudyopediaDemo { public static void main(String args[]) { int value; String msg1 = "Welcome to USA!"; String msg2 = "Welcome to USA!"; String msg3 = "Welcome to Australia!"; String msg4 = "Welcome to AUSTRALIA"; System.out.println("String one: " +msg1); System.out.println("String two: " +msg2); System.out.println("String three: " +msg3); System.out.println("String four: " +msg4); value = msg1.compareToIgnoreCase( msg2 ); System.out.println(value); value = msg2.compareToIgnoreCase( msg3 ); System.out.println(value); value = msg3.compareToIgnoreCase( msg4 ); System.out.println(value); } } |
Output
The following is the output,
No Comments