Java String equals() Method

You are Here:

Java String equals()

The equals() method checks whether the two specified String objects have the same value or not.

Note: Both, == and Equals() method compares the content of strings. So, there is no difference between them.

Note: This method is case-sensitive.

Example

Java Compiler
public class myClass { public static void main(String[] args) { String str1 = "JOHN DOE"; String str2 = "john doe"; String str3 = "JOHN DOE"; System.out.println(str1.equals(str2)); System.out.println(str1.equals(str3)); } }

Output

false true

Syntax

public bool str1.equals(str2)

Parameter Values

ValueTypeExplanation
str1RequiredSpecifies the string to be compared.
str2RequiredSpecifies the string to be compared.

Return Value

ValueExplanation
trueIf the two specified String objects have the same value.
falseIf the two specified String objects does not have the same value.

Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on Java with examples for quick and easy learning.

We are working to cover every Single Concept in Java.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author