Java Integer shortValue() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Integer

Definition

In Java, boxed.shortValue() converts an Integer to a primitive short, a 16-bit number from -32768 to 32767. The method belongs to Number, so it exists since Java 1.1.

If the value is outside that range, nothing is thrown. Java keeps only the low 16 bits, so the result can look very different from the original number.

An instance method of java.lang.Integer (since Java 1.1): call it on an Integer object. Integer lives in java.lang, so no import is needed.

Syntax

Call it on an Integer. It takes no arguments.

Java
Integer a = 100;
short x = a.shortValue();      // 100
Integer b = 40000;
short y = b.shortValue();      // -25536 (wrapped!)
CallWhat it does
boxed.shortValue()The low 16 bits as a short.
(short) iThe same narrowing for a primitive int.
Short.MIN_VALUE / Short.MAX_VALUEThe limits of short: -32768 and 32767.
i >= Short.MIN_VALUE && i <= Short.MAX_VALUEA check that the value fits before you narrow it.

shortValue() never throws. If the value does not fit, the result silently wraps around.

Library declarations
Java
// java.lang.Integer
public short shortValue()

// Inherited contract from java.lang.Number

Parameters

ParameterDescription
NoneshortValue() takes no parameters.

Return Value

Return ValueDescription
shortThe low 16 bits of the value, read as a signed number from -32768 to 32767.

Compare with Similar Methods

Related conversions:

MethodHow it differs
byteValue()Narrows further, to 8 bits.
intValue()Returns the full 32-bit value.
longValue()Widens instead of narrowing; never loses information.
Character.charValue()Unwraps a Character to a char.

Java Examples

Example 1 — Narrow Numbers to short

Convert a mix of small and large values and see which ones survive.

Java
public class IntegerShortValueDemo {
    public static void main(String[] args) {
        Integer[] numbers = {100, -100, 32767, 32768, 40000, 70000, -40000};

        for (Integer number : numbers) {
            System.out.println(number + " -> " + number.shortValue());
        }
    }
}

How It Works

  1. In range stays the same. 100, -100, and 32767 fit in a short, so they come back unchanged.
  2. One past the top. 32768 needs a 17th bit, which is dropped, so the value wraps to -32768.
  3. 40000 and 70000. Subtracting 65536 gives -25536 for 40000, and 70000 leaves 4464 after the wrap.
  4. Negative values wrap the other way. -40000 is below -32768, so adding 65536 gives 25536.

Example 2 — See the Pattern Behind the Wrap

Print values around multiples of 65536 to see that short repeats every 16 bits.

Java
public class IntegerShortValueWrap {
    public static void main(String[] args) {
        Integer[] numbers = {65535, 65536, 65537, 98304, 131072};

        for (Integer number : numbers) {
            short s = number.shortValue();
            System.out.println(number + " -> " + s + ", low 16 bits: "
                    + Integer.toHexString(number & 0xFFFF));
        }
    }
}

How It Works

  1. Only 16 bits survive. The hex column shows the low 16 bits that shortValue() keeps.
  2. 65535 is all ones. Its low 16 bits are ffff, which a signed short reads as -1.
  3. 65536 is a clean wrap. The low 16 bits are all zero, so the result is 0; 65537 gives 1.
  4. Halfway points. 98304 keeps 8000, the pattern for -32768, while 131072 is two full wraps and gives 0.

Example 3 — Check the Range Before You Narrow

Write a helper that narrows only when the value fits, and reports a problem otherwise.

Java
public class IntegerShortValueSafe {
    static String toShort(Integer value) {
        if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) {
            return "short " + value.shortValue();
        }
        return "does not fit";
    }

    public static void main(String[] args) {
        Integer[] numbers = {500, 32767, 32768, -32768, -32769};
        for (Integer number : numbers) {
            System.out.println(number + ": " + toShort(number));
        }
        System.out.println("limits: " + Short.MIN_VALUE + " to " + Short.MAX_VALUE);
    }
}

How It Works

  1. Test first. The helper compares the number with Short.MIN_VALUE and Short.MAX_VALUE before it narrows.
  2. Edges that fit. 32767 and -32768 are exactly the limits, so both are accepted.
  3. One step outside. 32768 and -32769 are rejected instead of wrapping to a surprising value.
  4. Constants show the limits. Short.MIN_VALUE and Short.MAX_VALUE are -32768 and 32767.

Frequently Asked Questions

It returns the low 16 bits of the Integer as a primitive short, which holds numbers from -32768 to 32767.
No exception is thrown. The upper bits are dropped, so 40000 becomes -25536.
Compare it with Short.MIN_VALUE and Short.MAX_VALUE before narrowing, as in value >= Short.MIN_VALUE && value <= Short.MAX_VALUE.
For an Integer they give the same result. The cast works on a primitive int; shortValue() works on an Integer object.
Rarely. short saves memory in large arrays, but Java promotes it to int in arithmetic, so int is the usual choice.

Next: signum()

Get -1, 0, or 1 for a negative, zero, or positive number.

signum() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

7 people found this page helpful