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) code.
Syntax:
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.
// Java program to demonstrate valueOf() method of BigInteger import java.math.BigInteger; public class GFG { public static void main(String[] args) { // Creating 2 BigInteger objects BigInteger b1, b2; // apply valueOf() b1 = BigInteger.valueOf(456782765); b2 = BigInteger.valueOf(12345543); // print result System.out.println("Value of BigInteger b1: " + b1); System.out.println("Value of BigInteger b2: " + b2); } } |
Value of BigInteger b1: 456782765 Value of BigInteger b2: 12345543
Example 2: Apply valueOf() by creating BigInteger object.
// Java program to demonstrate valueOf() method of BigInteger import java.math.BigInteger; public class GFG { public static void main(String[] args) { // Creating BigInteger objects BigInteger b1, b2, b3; // create bigInteger with some value b1 = new BigInteger("532721"); // apply valueOf() b2 = b1.valueOf(234567898); b3 = b2.valueOf(98765432); // print result System.out.println("Value of BigInteger 1: " + b2); System.out.println("Value of BigInteger 2: " + b3); } } |
Value of BigInteger 1: 234567898 Value of BigInteger 2: 98765432
Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#valueOf(long)
Recommended Posts:
- Integer valueOf() Method in Java
- BigDecimal valueOf() Method in Java
- TimeUnit valueOf() method in Java with Examples
- Data Conversion Using valueOf() method in Java
- DayOfWeek valueOf() method in Java with Examples
- Locale.Category valueOf() method in Java with Examples
- Java.lang.Long.valueOf() method with examples
- Locale.FilteringMode valueOf() method in Java with Examples
- BigInteger xor() Method in Java
- BigInteger or() method in Java
- BigInteger mod() Method in Java
- BigInteger pow() Method in Java
- BigInteger abs() Method in Java
- BigInteger and() Method in Java
- BigInteger not() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai

