Java Short.equals(Object obj) example

Java Short.equals(Object obj) example

By Yashwant Chavan, Views 3, Date 24-Apr-2018

In this java tutorial, You will learn how to use equals(Object obj) method of Short class. 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. This method returns true if the objects are the same, false otherwise.

tags Java

Compares this object to the specified object.


public boolean equals(Object obj)


obj - the object to compare with.


true if the objects are the same; false otherwise.

Java Short equals(Object obj) example

  • Assign two short values.
  • Create an instance of short values e.g new Short(value);
  • firstValue.equals(secondValue);It will return true if firstValue and secondValue are equal, Otherwise false.
  • Print the result.
package com.technicalkeeda;

public class App {

    public static void main(String[] args) {

        short value1 = 20;
        Short firstValue = new Short(value1);

        short value2 = -20;
        Short secondValue = new Short(value2);

        boolean result = firstValue.equals(secondValue);

        System.out.println("firstValue and secondValue equal? :- " + result);


firstValue and secondValue equal? :- false

Suggested Posts



Hi there! I am founder of and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][]