Java Number.shortValue() Method Last Updated : 15 May, 2025 Comments Improve Suggest changes Like Article Like Report The shortValue() is an inbuilt method in Java from the java.lang.Number class. This method is used to convert the current number object into a short primitive type. This may involve rounding or truncation because the short data type in Java is a 16-bit signed integer with a value range from -32,768 to 32,767. And if we convert a number larger than this range, it can cause data loss.Syntax of shortValue() Methodpublic abstract short shortValue();Parameters: This method does not accept any parameters. Return value: This method returns the numeric value represented by this object after conversion to type short.Examples of Java Number.shortValue() MethodExample 1: In this example, we are going to convert the larger values. Java // Java program to demonstrate // shortValue() with large float and double values import java.lang.Number; public class Geeks { public static void main(String[] args) { // Large float number Float f = new Float(7854123456f); short shortFromFloat = f.shortValue(); System.out.println("Float to short: " + shortFromFloat); // Large double number Double d = new Double(98774856); short shortFromDouble = d.shortValue(); System.out.println("Double to short: " + shortFromDouble); } } OutputFloat to short: -1 Double to short: 12104 Explanation: Here, both values exceeds the limit of the short data type so, the results wraps around due to data loss.Example 2: In this example, we are going to do safe conversions with smaller values. Java // Java program to demonstrate // shortValue() with smaller, within-range values import java.lang.Number; public class Geeks { public static void main(String[] args) { // Float value within short range Float f = new Float(78f); System.out.println("Float to short: " + f.shortValue()); // Double value within short range Double d = new Double(56.23); System.out.println("Double to short: " + d.shortValue()); } } OutputFloat to short: 78 Double to short: 56 Explanation: Here, the values are withing the valid short range. And the decimal values like 56.23 are truncated to 56 before converting.Important Points:This method is very useful when we need to extract numeric object to a short data type.But we should cautiously use this method when working with large or floating point numbers because it can result in overflow. Comment More infoAdvertise with us Next Article Integer shortValue() Method in Java T Twinkl Bajaj Follow Improve Article Tags : Java Java - util package Java-Functions Practice Tags : Java Similar Reads Short shortValue() Method in Java The shortValue() is an inbuilt method of the Short class in Java and is used to return the Short value of this value. Syntax: public short shortValue() Parameters: The method does not take any parameter. Return Value: The method returns the numeric value represented by this object after conversion t 2 min read Number.shortValue() method in java with examples The shortValue() is an inbuilt method in Java from the java.lang.Number class. This method is used to convert the current number object into a short primitive type. This may involve rounding or truncation because the short data type in Java is a 16-bit signed integer with a value range from -32,768 2 min read Integer shortValue() Method in Java The Integer.shortValue() is an inbuilt method of java.lang which returns the value of this Integer in the short type . Syntax: public short shortValue() Parameters: The method does not take any parameters. Return Value: The method returns the integer value represented by this object after converting 2 min read BigDecimal shortValueExact() Method in Java The java.math.BigDecimal.shortValueExact() is an inbuilt method in java that converts this BigDecimal to a short, checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for a short result then an ArithmeticException is thrown. Syntax: public s 2 min read Byte shortValue() method in Java with examples The shortValue() method of Byte class is a built in method in Java which is used to return the value of this Byte object as short. Syntax ByteObject.shortValue() Return Value: It returns the value of ByteObject as short. Below is the implementation of shortValue() method in Java: Example 1: Java // 2 min read Short compare() method in Java The compare() method of Short class is used to compare two primitive short values for numerical equality. As it is a static method therefore it can be used without creating any object of Short. Syntax: public static int compare(short x, short y) Parameters: This method accepts two parameters: x: whi 2 min read Like