Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

String compare by equals Method in Java



The equals() method of the String class compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.

Example

 Live Demo

public class Test {
   public static void main(String args[]) {
      Integer x = 5;
      Integer y = 10;
      Integer z =5;
      Short a = 5;
      System.out.println(x.equals(y));
      System.out.println(x.equals(z));
      System.out.println(x.equals(a));
   }
}

Output

false
true
false
Updated on: 2019-07-30T22:30:21+05:30

141 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements