BigInteger max() and min() Methods in Java Last Updated : 04 Dec, 2018 Comments Improve Suggest changes Like Article Like Report Prerequisite: BigInteger Basics BigInteger max() method: The max() method of the BigInteger returns the BigInteger whose value is the greater between current BigInteger and BigInteger passed as a parameter to the method. If both the values are equal, either may be returned. There is a similar method compareTo() available on BigInteger class. The max() method is different than compareTo() in a way that in the compareTo() method we have to interpret the result while on the max method, the biggest BigInteger is already returned. Syntax: public BigInteger max(BigInteger val) Parameters: The method accepts one parameter val which refers to the value with which the maximum is to be computed. Return Value: The method returns the BigInteger whose value is the greater of this and val. If they are equal, either may be returned. Below program illustrate max() method of BigInteger class. Java /* *Program Demonstrate max() method of BigInteger */ import java.math.*; public class GFG { public static void main(String[] args) { // Create 2 BigInteger objects BigInteger biginteger=new BigInteger("8976543245"); BigInteger val=new BigInteger("9248040402"); // Call max() method to find greater value // between two BigIntegers. BigInteger biggerInteger = biginteger.max(val); String result = "Bigger Integer between "+biginteger+" and " +val+ " is " +biggerInteger; // Prints the result System.out.println(result); } } Output: Bigger Integer between 8976543245 and 9248040402 is 9248040402 BigInteger min() method: The min() method of the BigInteger returns the BigInteger whose value is the lesser between current BigInteger and BigInteger passed as parameter to method. If both the values are equal, either may be returned. There is a similar method compareTo() available on BigInteger class . The min() method different than compareTo() in a way that in the compareTo() method we have to interpret the result while on the min() method, the smallest BigInteger will be returned. Syntax: public BigInteger min(BigInteger val) Parameters: The method accepts one parameter val which refers to the value with which the minimum is to be computed. Return Value: The method returns the BigInteger whose value is the lesser of this and val. If the values are equal, either may be returned. Below program illustrate min() method of BigInteger class. Java /* *Program Demonstrate min() method of BigInteger */ import java.math.*; public class GFG { public static void main(String[] args) { // Create 2 BigInteger objects BigInteger biginteger=new BigInteger("5782539631"); BigInteger val=new BigInteger("3592633823"); // Call min() method to find lesser value // between two BigIntegers. BigInteger biggerInteger = biginteger.min(val); String result = "lesser Integer between "+biginteger+" and " +val+ " is " +biggerInteger; // Prints the result System.out.println(result); } } Output: lesser Integer between 5782539631 and 3592633823 is 3592633823 Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#max(java.math.BigInteger) https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#min(java.math.BigInteger) Comment More infoAdvertise with us Next Article BigInteger max() and min() Methods in Java A AmanSingh2210 Follow Improve Article Tags : Java Java-lang package Java-Functions java-math Java-BigInteger Java-math-package +2 More Practice Tags : JavaJava-BigInteger Similar Reads BigInteger and() Method in Java The java.math.BigInteger.and(BigInteger val) method returns a BigInteger whose value is bitwise-AND of two BigIntegers. This method returns a negative number if both of the BigIntegers are negative. The and() method applies bitwise-AND operation upon the current bigInteger and bigInteger passed as p 2 min read BigInteger abs() Method in Java prerequisite : BigInteger Basics The java.math.BigInteger.abs() method returns absolute value of a BigInteger. By using this method one can find absolute value of any large size of numerical data stored as BigInteger. Syntax: public BigInteger abs() Parameters: The method does not take any parameter 1 min read BigInteger or() method in Java Prerequisite: BigInteger Basics The java.math.BigInteger.or(BigInteger val) method is used to perform bitwise OR of two BigIntegers. One of the BigInteger is passed in parameter and the other on which the function is called. This method returns a negative number if either of the BigIntegers used wit 2 min read BigInteger valueOf() Method in Java The java.math.BigInteger.valueOf(long value) method returns a BigInteger whose value is equal to value of long passed as parameter. This method is static method so It is not necessary to create object of BigInteger class to use this method.we can call this function by BigInteger.valueOf(long value) 2 min read BigDecimal max() Method in Java The java.math.BigDecimal.max(BigDecimal val) method in Java is used to compare two BigDecimal values and return the maximum of the two. This is opposite to BigDecimal max() method in Java. Syntax: public BigDecimal max(BigDecimal val) Parameters: The function accepts a BigDecimal object val as param 2 min read Like