Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java equals() Method

Java equals() Method

Java Number ClassThe Java Number class


The equals() method determines whether a Number object is equal to the method's argument.

Syntax



public boolean equals(Object o)

Parameters

o -- any object.

Return Value

Returns True if the Number object is not null and both the type and value match the method's argument; otherwise returns False.

Double and Float objects have some additional conditions; refer to the API documentation:JDK 1.6.

Example

Example

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

)

)

;

       

}

}

Compile the above program; the output is:



false

true

false


Java Number ClassThe Java Number class