Java Data Type Tutorial - Java String.equals(Object anObject)








Syntax

String.equals(Object anObject) has the following syntax.

public boolean equals(Object anObject)

Example

In the following code shows how to use String.equals(Object anObject) method.

public class Main {
  public static void main(String args[]) {
  String s1 = "Java2s.com";
  String s2 = "java2s.com";
  String s3 = "jAva2s.com";
  String s4 = "java2s.COM";
  System.out.println(s1 + " equals " + s2 + " -> " + s1.equals(s2));
  System.out.println(s1 + " equals " + s3 + " -> " + s1.equals(s3));
  System.out.println(s1 + " equals " + s4 + " -> " + s1.equals(s4));
  }/*from  w  w w. j  ava 2 s  . c o  m*/
}

The code above generates the following result.