Write a program to find the two string are equals or not by ignore the case.
Input (Input string1, Input string2) |
Output |
MERITCAMPUS mericcampus |
true |
AndhraPradesh ANDHRApradesh |
true |
Virat Kohli virat KoHlI |
true |
"" "" |
true |
null null |
true |
Apple Mango |
false |
Boy Girl |
false |
class Stringcomparisionbyignorecase
{
public static void main(String s[])
{
String inputString1 = "MeritCampus";
String inputString2 = "meritcampus";
boolean result = areStringsEqualsByIgnoreCase(inputString1, inputString2);
System.out.println("The input strings "+inputString1+ " and "+inputString2+" are equals : "+result);
}
public static boolean areStringsEqualsByIgnoreCase(String inputString1, String inputString2)
{
boolean result = false;
return result;
}
}
Topic:
Java String Comparison Methods - Equals and EqualsIgnoreCase
If you need explanation Read this topic
If you need Answer Take test on this topic
User comments below. All of them might not be correct.
here we have to compare two strings that whether they are equal irrespective of their case....... upper or lower... so for comparing we will use equalsIgnoreCase()->> wich compares two stri g for equality without considering their case..... Two strings are considered equal ignoring case if they are of the same length, and corresponding characters in the two strings are equal ignoring case...........Syntax -:Here is the syntax of this method:public boolean equalsIgnoreCase(String anotherString)...........result=input1.equalsIgnoreCase(input2) ......return result
Posted by Asma Mujtaba Khan 2015-01-08 06:07:59
we need to compare the 2 Strings irrespective of their case..we can do this by using the direct method equalsIgnoreCase()
Ex:string1.equalsIgnoreCase(string2)
Case 2: we can write manual code for this by comparing the each char..
if both strings are not in same size return false (if( s1.length()!=s2.length())) return false;
take for loop start comparing the each char
if(s1.charAt(i)!=s2.charAt(i)) return false;
After coming out of the loop return true;
Posted by Uday Kumar 2015-01-08 09:37:37
According to Question .. we need to Compare two Strings Irrespective of Case and also if the Value is Null... So first we need to handle null .. So use a if condition such that if both are nulls then result must be "true" .. Now we Consider the Situations where the Strings are Not Nulls ... For this we Write else if Condition and Convert those two to Upper Case and Use Equals method ... if pass then result is true... Else leave the Result as it is (false) . ..
Posted by ?????????? ????? 2015-01-09 08:08:06
This dose is now closed and the winners are Asma Mujtaba Khan, for 'First Correct Comment', ?????????? ?????, for 'Second Correct Comment'. The 'lucky liker' is Uday Kumar. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.
Posted by Merit Campus 2015-01-10 03:18:58