Advertisement
|
---|
Performs a case-insensitive equality check between the invoked String object value and the value in String str and returns an Boolean -
|
// Program to find whether value of String is same as value value of another String(Ignoring cases)
class IgnoreCase
{
public static void main(String[] ar)
{
String str1 = new String("WELCOME");
String str2 = new String("welcome");
String str3 = new String("Welcome");
String str4 = new String("WelComE");
System.out.println("First String is " + str1);
System.out.println("Second String is " + str2);
System.out.println("Third String is " + str3);
System.out.println("Fourth String is " + str4);
System.out.println("Values in first and second String equal? " + str1.equalsIgnoreCase(str2));
System.out.println("Values in first and third String equal? " + str1.equalsIgnoreCase(str3));
System.out.println("Values in first and fourth String equal? " + str1.equalsIgnoreCase(str4));
}
}
First String is WELCOME
Second String is welcome
Third String is Welcome
Fourth String is WelComE
Values in first and second String equal? true
values in first and third String equal? true
Values in first and fourth String equal? true
Advertisement
// Displaying the difference between equals() and equalsIgnoreCase() methods.
class IgnoreCase
{
public static void main(String[] ar)
{
String str1 = new String("Good Day");
String str2 = new String("GOOD DAY");
System.out.println("First String is " + str1);
System.out.println("Second String is " + str2);
//Case-sensitive check on values of first and second String object
System.out.println("equals() on first and second String object? " + str1.equals(str2));
//Case-insensitive check on values of first and second String object
System.out.println("equalsIgnoreCase() on first and second String object? " + str1.equalsIgnoreCase(str2));
}
}
First String is Good Day
Second String is GOOD DAY
equals() method on first and second String object? false
equalsIgnoreCase() on first and second String object? true
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement