Java.lang.Long.equals() Method


Description

The java.lang.Long.equals() method compares this object to the specified object. The result is true if and only if the argument is not null and is a Long object that contains the same long value as this object.

Declaration

Following is the declaration for java.lang.Long.equals() method

public boolean equals(Object obj)

Parameters

obj − This is the object to compare with.

Return Value

This method returns true if the objects are the same, else false.

Exception

NA

Example

The following example shows the usage of java.lang.Long.equals() method.

package com.tutorialspoint;

import java.lang.*;

public class LongDemo {

   public static void main(String[] args) {

      Long obj1 = new Long(79845);
      Long obj2 = new Long(79800);
      System.out.print("Is obj1 and obj2 equal ? ");
      System.out.println(obj1.equals(obj2));

      obj1 = new Long(45469);
      obj2 = new Long(45469);
      System.out.print("Is obj1 and obj2 equal ? ");
      System.out.println(obj1.equals(obj2));
   }
}  

Let us compile and run the above program, this will produce the following result −

Is obj1 and obj2 equal ? false
Is obj1 and obj2 equal ? true
java_lang_long.htm
Advertisements