- Java.math 包額外內容
- Java.math - 列舉
- Java.math - 討論
Java.math.BigInteger.valueOf() 方法
描述
java.math.BigInteger.valueOf(long val) 返回一個 BigInteger,其值等於指定的 long。這種“靜態工廠方法”優於 (long) 建構函式,因為它允許重複使用常用的 BigInteger。
宣告
以下是對 java.math.BigInteger.valueOf() 方法的宣告。
public static BigInteger valueOf(long val)
引數
val - 要返回的 BigInteger 的值。
返回值
此方法返回具有指定值的一個 BigInteger。
異常
無
示例
以下示例說明了如何使用 math.BigInteger.valueOf() 方法。
package com.tutorialspoint;
import java.math.*;
public class BigIntegerDemo {
public static void main(String[] args) {
// create a BigInteger object
BigInteger bi;
// create and assign value to Long object
Long l = new Long(123456789L);
// assign the biginteger value of l to bi
// static method is called using class name
bi = BigInteger.valueOf(l);
String str = "BigIntger value of Long " + l + " is " +bi;
// print bi value
System.out.println( str );
}
}
我們編譯並執行上述程式,它將產生以下結果 -
BigIntger value of Long 123456789 is 123456789
java_math_biginteger.htm
廣告