java.lang.String equals()


This java tutorial shows how to use the equals() method of java.lang.String class. This method returns boolean data type which checks if the String is equals to the object input parameter on this method. This generally checks if the string is the same character sequence as that of the object parameter. This method is an override from of the equals method inherited from Object class.

Method Syntax :

public boolean equals(Object anObject)

Parameter Input :

  • anObject – this is a parameter object which we are trying to compare on our String.

Method Returns :

This method returns boolean datatype that throws true if the String and Object parameter input is the same in terms of character sequence, false if otherwise.

Java Code Example :

This example source code demonstrates the use of equals() method of String class. This checks the equality of two strings by comparing it with equals method of String class. As you have already noticed we have used the conversion of char array to String.

Sample Output :

Running the equals() example source code will give you the following output

java string equals ignore case method example

java string equals ignore case method example

Suggested Reading List :