Java convert short to byte

Tags: short byte

In this Java core tutorial we learn how to convert a short value into a byte value with different solutions in Java programming language.

Table of contents

  1. How to cast short to byte value
  2. Using Short.byteValue() method

How to cast short to byte value

In this first solution to convert a short to byte value we just simple cast a short variable to a byte variable as the example Java code below.

ConvertShortToByteExample1.java

public class ConvertShortToByteExample1 {
    public static void main(String... args) {
        short shortValue = 67;

        byte byteValue = (byte)shortValue;

        System.out.println("short value: " + shortValue);
        System.out.println("byte value: " + byteValue);
    }
}
The output as below.
short value: 67
byte value: 67

Using Short.byteValue() method

In this second solution, we use the Short.byteValue() method to return a byte value from a given Short object as the following Java code.

ConvertShortToByteExample2.java

public class ConvertShortToByteExample2 {
    public static void main(String... args) {
        Short shortValue = 69;

        byte byteValue = shortValue.byteValue();

        System.out.println("short value: " + shortValue);
        System.out.println("byte value: " + byteValue);
    }
}
The output as below.
short value: 69
byte value: 69

Happy Coding 😊

Java convert short to long

Java convert short to BigInteger

Java convert short to BigDecimal

Java convert short to char

Java convert long to short

Java convert char to short

Java convert byte to short