String.equals() method checks the equality between two object and returns in Boolean values.
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