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.
String methods in Java
String method- indexof
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...

1 Response

  1. August 6, 2015

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