Java String equals() method example

HQ » Java Tutorial » java.lang » String » equals() method example
Java String equals() method example 2018-02-19T12:43:37+00:00

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 :


Contact Info


Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.