Java String equalsIgnoreCase()

Java String equalsIgnoreCase()

The String equalsIgnoreCase() method compares the two given strings on the basis of content of the string irrespective of case of the string. It is like equals() method but doesn’t check case. If any character is not matched, it returns false otherwise it returns true.


Signature

  1. public boolean equalsIgnoreCase(String str)

Parameter

str : another string i.e. compared with this string.


Returns

It returns true if characters of both strings are equal ignoring case otherwise false.


Java String equalsIgnoreCase() method example

  1. public class EqualsIgnoreCaseExample{
  2. public static void main(String args[]){
  3. String s1=“javatpoint”;
  4. String s2=“javatpoint”;
  5. String s3=“JAVATPOINT”;
  6. String s4=“python”;
  7. System.out.println(s1.equalsIgnoreCase(s2));//true because content and case both are same
  8. System.out.println(s1.equalsIgnoreCase(s3));//true because case is ignored
  9. System.out.println(s1.equalsIgnoreCase(s4));//false because content is not same
  10. }}

Test it Now

true
true
false
java for beginners
java for beginners
java for beginners
CodSir //course // books
...

WikiSir

Java String equalsIgnoreCase() The String equalsIgnoreCase() method compares the two given strings on the basis of content of the string irrespective of case of the string. It is like equals() method but doesn’t check case. If any character is not matched, it returns false otherwise it returns true. Signature public boolean equalsIgnoreCase(String str) Parameter str : another string i.e. compared with […]

Tags:

....
...