Short equals() in Java

equals(): This method is available in java.lang.System class of Java.

Syntax:

boolean java.lang.Short.equals(Object obj)

This method takes one argument of type Object as its parameter. This method compares this object to the specified object. The result is true if and only if the argument is not null and is a Short object that contains the same short value as this object.

Parameters: One parameter is required for this method.

obj: the object to compare with.

Returns: true if the objects are the same; false otherwise.

Exceptions: NA

Approach

Java

public class Shortequals {
    public static void main(String[] args) {

        Short short1 = 1;
        Object obj = 2;
        System.out.println(short1.equals(obj));
    }
}

Output:

false


No comments:

Post a Comment