Java convert long to BigInteger

Tags: BigInteger BigInteger valueOf long Convert

In this Java core tutorial we learn how to convert a long value to a BigInteger value using the java.math.BigInteger.valueOf() method.

How to convert long to BigInteger

To convert a given long value to BigInteger we can use the method java.math.BigInteger.valueOf() which instantiates a BigInteger from a given long value.

ConvertLongToBigIntegerExample.java

import java.math.BigInteger;

public class ConvertLongToBigIntegerExample {
    public static void main(String... args) {
        long longValue = 1234567890L;

        BigInteger value = BigInteger.valueOf(longValue);

        System.out.println("BigInteger value: " + value);
    }
}
The output is:
BigInteger value: 1234567890

Happy Coding 😊

Java convert BigInteger to long

Convert long to String in Java

Convert long to float in Java

Convert long to int in Java

Convert long to double in Java