Java get maximum value of two BigInteger values

Tags: BigInteger BigInteger max

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

How to get max BigInteger value

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

GetMaxBigIntegerExample.java

import java.math.BigInteger;

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

        BigInteger maxValue = value1.max(value2);

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

Happy Coding 😊