Home Tutorials Java StringExamples java.lang.string.equalsignorecase
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

java.lang.string.equalsignorecase

Advertisement
Given is a simple example on equalsIgnoreCase() method in Java

equalsignorecase() method works similar to equals() method in Java.. the only difference is that equalsignorecase() method simply ignore the case semstivity and examines without considering it. For examples, equalsignorecase() method considere both "java tutorial" and "JAVA TUTORIAL" equals.

Syntax for string.equalsignorecase() method

public boolean equalsIgnoreCase(String anotherString)

java.lang.string.equalsignorecase() method returns "true" if the strings are not empty and of equal lengths with similar coresponding characters...otherwise it returns false.

a simple example of equalsignorecase method in java:

public static void main(String[] args){

String str1 = "Java Tutorials";

String str2 = "Tutorials in Java";

String str3 = "JAVA TUTORIALS";

boolean equals1 = str1.equalsIgnoreCase(str2);

boolean equals2 = str1.equalsIgnoreCase(str3);

System.out.println("\"" + str1 + "\" is equals to \""
+ str2 +
"\" - " + equals1);

System.out.println("\"" + str1 + "\" is equals to \""
+ str3 +
"\" - " + equals2);

}

the output is:

"Java Tutorials" is equals to "Tutorials in Java" - false

"Java Tutorials" is equals to "JAVA TUTORIALS" - true

Related Links

String equalsIgnoreCase(String Str)

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 17, 2005

Ask Questions?    Discuss: java.lang.string.equalsignorecase  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com