Java Short.longValue() example

Java Short.longValue() example

By Yashwant Chavan, Views 9, Date 17-May-2018

In this java tutorial, You will learn how to use longValue() method of Short class. This method, Returns the value of this Short as a long. This method returns the numeric value represented by this object after conversion to type long.

tags Java

Returns the value of this Short as a long.

Syntax

public long longValue()

Returns

The numeric value represented by this object after conversion to type long.

Java Short longValue() example

  • Assign two short values.
  • Create an instance of short values e.g new Short(value);
  • firstValue.longValue();It will return the long value for firstValue.
  • secondValue.longValue();It will return the long value for secondValue.
  • Print the long values.
package com.technicalkeeda;

public class App {

    public static void main(String[] args) {

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

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

        long result1 = firstValue.longValue();
        long result2 = secondValue.longValue();

        System.out.println("The long value for firstValue :- " + result1);
        System.out.println("The long value for secondValue :- " + result2);
    }
}

output

The long value for firstValue :- 50
The long value for secondValue :- -20

Suggested Posts

Yashwant

Yashwant

Hi there! I am founder of technicalkeeda.com 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][gmail.com]