Java-math-biginteger-valueof

提供:Dev Guides
移動先:案内検索

Java.math.BigInteger.valueOf()メソッド

説明

  • java.math.BigInteger.valueOf(long val)*は、指定されたlongの値と等しいBigIntegerを返します。 この「静的なファクトリメソッド」は、頻繁に使用されるBigIntegerの再利用を可能にするため、(長い)コンストラクタよりも優先して提供されます。

宣言

以下は* java.math.BigInteger.valueOf()*メソッドの宣言です。

public static BigInteger valueOf(long val)

パラメーター

*val* -返すBigIntegerの値。

戻り値

このメソッドは、指定された値を持つBigIntegerを返します。

例外

NA

次の例は、math.BigInteger.valueOf()メソッドの使用法を示しています。

package com.finddevguides;

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