Home Tutorial Java StringExamples String.equals()

 
 

String.equals()
Posted on: March 22, 2005 at 12:00 AM
String.equals() method checks the equality between two object and returns in Boolean values.

In Java programming language, equals() is method of string class that is used for comparison between two objects. It always returns the output in Boolean value "true or false". You can use the method to check the equality between the given objects... and the method returns "true" in case of both the objects are equal otherwise it will return "false".

a simple example of equals() method:

public class StringTrim {

public static void main(String[] args) {

String one = "Java Examples";

String two = "Java Examples Code";

String Three = "Java Examples";

String Four = "Java";

System.out.println(one + " is equals to " + two + " -> " + one.equals(two));

System.out.println(one + " is equals to " + Three + " -> " + one.equals(Three));

System.out.println(one + " is equals to " + Four + " -> " + one.equals(Four));

}

}

the output is:

Java Examples is equals to Java Examples Code -> false

Java Examples is equals to Java Examples -> true

Java Examples is equals to Java -> false

Related Examples:
Compare strings example

Related Tags for String.equals():


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.