Java convert short to BigInteger
Tags: short BigInteger
In this Java core tutorial we learn how to convert a short value into a BigInteger object in Java programming language.
How to convert short to BigInteger in Java
In Java, we can use the BigInteger.valueOf(long val) static method to instantiate a new BigInteger object from a given byte value as the following Java program.
ConvertShortToBigIntegerExample1.java
import java.math.BigInteger;
public class ConvertShortToBigIntegerExample1 {
public static void main(String... args) {
short shortValue = 987;
BigInteger bigInteger = BigInteger.valueOf(shortValue);
System.out.println("short value: " + shortValue);
System.out.println("BigInteger value: " + bigInteger);
}
}
short value: 987
BigInteger value: 987
Happy Coding 😊