equals() - String Methods in Java


This article is a part of String Methods in Java.
The equals() method compares the two strings if they are same. The parameter passed in this method is an object which points to a string which needs to be compared.


Return type

The return type for equals() method is Boolean. It returns true if the strings are same and false otherwise.
Let us look at an example code.


Output

Let us look at the output of the above.

String Methods equals()
Fig.1- String Method - equals()

equalsIgnoreCase()

The equalsIgnoreCase() method compares the two strings if they are same, ignoring the lower and upper case differences. The parameter passed in this method is an object which points to a string which needs to be compared.

Return type

The return type for equalsIgnoreCase() method is Boolean. It returns true if the strings are same, ignoring the upper and lower case differences and false otherwise.
Let us look at an example code.


Output

Let us look at the output of the above.

String Methods equalsIgnoreCase()
Fig.2- String Method - equalsIgnoreCase()

Read More

Author : Satyam Kumar -



You will also like: