String methods – equals() and equalsIgnoreCase()

These methods are used to compare 2 string objects. If both String matches, returns true else false.

Equals():

Equals is used to compare 2 strings and it is case sensitive.
e.g. The Strings “JAVA” and “java” , result will be false.

Output:
Comparing val1 and val2 false
Comparing val2 and val3 false
Comparing val3 and val4 true

 

equalsIgnoreCase():

This is used to compare 2 strings and it is not case-sensitive.
e.g. The Strings “JAVA” and “java” , result will be true.

Output: Comparing val1 and val2 true
Comparing val2 and val3 false
Comparing val3 and val4 true
Ask Question
If you have any question, you can go to menu ‘Features -> Q&A forum-> Ask Question’.Select the desired category and post your question.
Print Friendly, PDF & Email
String methods in Java
String method- indexof
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

1 Response

  1. August 6, 2015

    […] boolean equals(Object anObject) […]