Convert int to short in Java

In this Java core tutorial, we learn how to convert int value into short value in Java via different solutions.

How to cast int to short value in Java

ConvertIntToShortExample1.java

public class ConvertIntToShortExample1 {
    public static void main(String[] args) {
        int value1 = 99;
        short value2 = (short)value1;

        System.out.println("int value: " + value1);
        System.out.println("short value: " + value2);
    }
}
The output is:
int value: 99
short value: 99

Using Integer.shortValue() method to get short value of an Integer object

ConvertIntToShortExample2.java

public class ConvertIntToShortExample2 {
    public static void main(String[] args) {
        Integer value1 = 27;
        short value2 = value1.shortValue();

        System.out.println("int value: " + value1);
        System.out.println("short value: " + value2);
    }
}
The output is:
int value: 27
short value: 27

Happy Coding 😊