java.lang.Long shortValue()

Description

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

Notes:

  • Overrides shortValue in class Number

Method Syntax

public static int shortValue()

Method Argument

Data Type Parameter Description
N/A N/A N/A

Method Returns

The shortValue() method of Long class returns the numeric value represented by this object after conversion to type short.

Compatibility

Requires Java 1.0 and up

Java Long shortValue() Example

Below is a simple java example on the usage of shortValue() method of Long class.

package com.javatutorialhq.java.examples;

/*
 * This example source code demonstrates the use of  
 * shortValue() method of Long class
 */

public class LongShortValueExample {

	public static void main(String[] args) {

		// Declare a new Long variable
		Long value = 123l;

		// get the shortValue() method result
		short result = value.shortValue();

		// print the result
		System.out.println("Result:" + result);
		
		/*
		 * Be careful on using this method
		 * Desired result might differ
		 * because of the narrowing concept
		 * of java language
		 */

	}

}

Sample Output

Below is the sample output when you run the above example.

Java Long shortValue() example output