Share on Google+Share on Google+


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



Posted on: March 22, 2005 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null