java.math.BigInteger valueOf(long val)
Description
On this document we will be showing a java example on how to use the valueOf(long val) method of BigInteger Class. Basically this method returns a BigInteger whose value is equal to that of the specified long. This “static factory method” is provided in preference to a (long) constructor because it allows for reuse of frequently used BigIntegers.
Method Syntax
public static BigInteger valueOf(long val)
Method Argument
Data Type | Parameter | Description |
---|---|---|
long | val | value of the BigInteger to return. |
Method Returns
The valueOf(long val) method returns a BigInteger with the specified value.
Compatibility
Requires Java 1.1 and up
Java BigInteger valueOf(long val) Example
Below is a java code demonstrates the use of valueOf(long val) method of BigInteger class. The example presented might be simple however it shows the behavior of the valueOf(long val) method.
package com.javatutorialhq.java.examples; import java.math.BigInteger; import java.util.Scanner; /* * A java example source code to demonstrate * the use of valueOf() method of BigInteger class */ public class BigIntegerValueOfExample { public static void main(String[] args) { long value = 1234; BigInteger equivalent = BigInteger.valueOf(value); System.out.println(equivalent.multiply(new BigInteger("2"))); } }