java tutorial - Java equals() method - java programming - learn java - java basics - java for beginners



Java numbers equals

Learn Java - Java tutorial - Java numbers equals - Java examples - Java programs

Description

The equals () method - Java numeric object invokes the methods equalent to the object that is passed as an argument.

Syntax

public boolean equals(Object o)
click below button to copy the code. By - java tutorial - team

Options

Detailed information about the parameters:

  • o - any object..

Return value

  • • In Java, equals () returns true if the argument does not have a null value, is an object of the same type and with the related numeric value.
  • There are some additional requirements, described in the Java API documentation, for double and float objects.

Sample Code

public class Test{ 

   public static void main(String args[]){
      Integer x = 10;
      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));
     }
}
click below button to copy the code. By - java tutorial - team

Output

true
false
false

Related Searches to java equals() method