Java- Strings provides us the facility to compare the Strings using equals() and equalsIgnoreCase() functions :
1. equals(): This function gives result in Boolean.If the two strings,which are going to be matched, are equal on the basis of characters then the result is true otherwise false.It also checks the Case sensitivity i.e.upper and lower case of the characters.
Syntax: Stringname.equals(Name of the String you want to compare);
2. equalsIgnoreCase(): This function gives result in Boolean.If the two string are equals on the basis of characters and it also ignore upper and lower case of the characters then the result is true otherwise false.
Syntax:Stringname.equalsIgnoreCase(Name of the String you want to compare);
WAP to show the use of equals() and equalsIgnoreCase() String functions in Java
class Equal
{
public static void main(String arg[])
{
String a="Koding";
String b="POINT";
String c="Koding";
String d="KODING";
System.out.println(a.equals(c));
System.out.println(a.equals(d));
System.out.println(a.equalsIgnoreCase(d));
}
}
The output goes here:
1. equals(): This function gives result in Boolean.If the two strings,which are going to be matched, are equal on the basis of characters then the result is true otherwise false.It also checks the Case sensitivity i.e.upper and lower case of the characters.
Syntax: Stringname.equals(Name of the String you want to compare);
2. equalsIgnoreCase(): This function gives result in Boolean.If the two string are equals on the basis of characters and it also ignore upper and lower case of the characters then the result is true otherwise false.
Syntax:Stringname.equalsIgnoreCase(Name of the String you want to compare);
WAP to show the use of equals() and equalsIgnoreCase() String functions in Java
class Equal
{
public static void main(String arg[])
{
String a="Koding";
String b="POINT";
String c="Koding";
String d="KODING";
System.out.println(a.equals(c));
System.out.println(a.equals(d));
System.out.println(a.equalsIgnoreCase(d));
}
}
The output goes here:
0 comments: