Java String compareToIgnoreCase Example
String class compareToIgnoreCase method example
String class compareToIgnoreCase method example. This example shows you how to use compareToIgnoreCase method.This method Compares two strings lexicographically, ignoring case differences.
Here is the code:-
/**
* @(#) CompareToIgnoreCase.java
*Program that Compares two strings lexicographically, ignoring case considerations.
* @Version 01-May-2008
* @author Rose India Team
*/
public class CompareToIgnoreCase
{
public static void main(String[] args)
{
String str1 = "Welcome to RoseIndia";
String str2 = "Welcome to RoseIndia team";
// Compare the two strings.
int result = str1.compareToIgnoreCase(str2);
if (result < 0)
{
System.out.println(str1 + " is less than " + str2);
}
else if (result == 0)
{
System.out.println(str1 +" is equal to " + str2);
}
else
{
System.out.println(str1 +" is greater than " + str2);
}
}
}
ecc |
null
|