Groovy – equals()

  • Post author:
  • Post category:Groovy
  • Post comments:0 Comments
Equal

The method determines whether the Number object that invokes the method is equal to the object that is passed as argument.

Syntax

public boolean equals(Object o)

Parameters

o – Any object.

Return Value

The methods returns True if the argument is not null and is an object of the same type and with the same numeric value.

Example

Following is an example of the usage of this method −

class Example { 
   static void main(String[] args) { 
      Integer x = 5; 
      Integer y = 10; 
      Integer z = 5; 
		
      //Comparison against an Integer of different value 
      System.out.println(x.equals(y));
		
      //Comparison against an Integer of same value 
      System.out.println(x.equals(z));  
   } 
}

When we run the above program, we will get the following result −

false 
true

Previous Page:-Click Here

Leave a Reply