Java.lang Package Classes

Java Long - shortValue() Method

The java.lang.Long.shortValue() method returns the value of this Long as a short after a narrowing primitive conversion.


public short shortValue()


No parameter is required.

Return Value

Returns the numeric value represented by this object after conversion to type short.




In the example below, the java.lang.Long.shortValue() method returns a Long object after conversion to type short.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    //creating Long objects
    Long val1 = 25l;
    Long val2 = -25l;

    //printing shortValue of the Long objects
    System.out.println("shortValue of the val1 is: " + val1.shortValue()); 
    System.out.println("shortValue of the val2 is: " + val2.shortValue());   

The output of the above code will be:

shortValue of the val1 is: 25
shortValue of the val2 is: -25

❮ Java.lang - Long