Convert short to int in Java

Tags: int short Integer Convert

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

Table of contents

  1. Assign short variable to int variable
  2. Using Integer.valueOf() method
  3. Using Short.intValue() method

Assign short variable to int variable

We can convert shot value into in value by simply assign directly a short variable to an int variable as following Java example.

ConvertShortToIntExample1.java

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

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

Using Integer.valueOf() method to instantiate int value from a short value

The following example Java program to show how to use the Integer.valueOf() method to convert a short value to an int value.

ConvertShortToIntExample2.java

public class ConvertShortToIntExample2 {
    public static void main(String[] args) {
        short value1 = 87;
        int value2 = Integer.valueOf(value1);

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

Using Short.intValue() method to get int value from an Short object

Given an Short object we can use Short.intValue() method to get the int value as below Java example.

ConvertShortToIntExample3.java

public class ConvertShortToIntExample3 {
    public static void main(String[] args) {
        Short value1 = 57;
        int value2 = value1.intValue();

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

Happy Coding 😊

Convert boolean to int

Convert char to int

Convert Character to int

Convert String to int

Convert float to int

Convert long to int

Convert byte to int

Convert double to int

Convert BigDecimal to int

Convert int to short

Convert String to short

Convert float to short

Convert double to short

Convert BigDecimal to short

Convert boolean to short

Convert BigInteger to short

Convert short to String

Convert short to float

Convert short to double

Convert int to String

Convert int to float

Convert int to long

Convert int to byte

Convert int to double

Convert int to BigDecimal