Java get minimum value of two BigInteger values

Tags: BigInteger BigInteger min

In this Java core tutorial we learn how to use the java.math.BigInteger.min() method to get the minimum value of two given BigInteger values.

How to get min BigInteger value

In the following Java program, we show you how to use the java.math.BigInteger.min() method to get the minimum value from two BigInteger values.

GetMinBigIntegerExample.java

import java.math.BigInteger;

public class GetMinBigIntegerExample {
    public static void main(String... args) {
        BigInteger value1 = new BigInteger("1234567890987654321");
        BigInteger value2 = new BigInteger("1234567890987654322");


        BigInteger minValue = value1.min(value2);

        System.out.println("BigInteger value 1: " + value1);
        System.out.println("BigInteger value 2: " + value2);
        System.out.println("BigInteger minimum value: " + minValue);
    }
}
The output is:
BigInteger value 1: 1234567890987654321
BigInteger value 2: 1234567890987654322
BigInteger minimum value: 1234567890987654321

Happy Coding 😊