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) code.
public static BigInteger valueOf(long val)
Parameter: This method accepts a single parameter value which is the value of the BigInteger to be created.
Return Value: This method returns the BigInteger whose value is equal to value of long passed as parameter.
Below programs illustrate valueOf(long value ) method of BigInteger class:
Example 1: To apply valueOf() without creating BigInteger Object.
Value of BigInteger b1: 456782765 Value of BigInteger b2: 12345543
Example 2: Apply valueOf() by creating BigInteger object.
Value of BigInteger 1: 234567898 Value of BigInteger 2: 98765432
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.