Java Data Type How to - Create BigInteger via long type variable








Question

We would like to know how to create BigInteger via long type variable.

Answer

//  ww w .jav  a2s . c om


    
import java.math.BigInteger;

public class Main {
  public static void main(String[] argv) throws Exception {
    // Create via a string
    BigInteger bi1 = new BigInteger("1234567890123456890");

    // Create via a long
    BigInteger bi2 = BigInteger.valueOf(123L);

    bi1 = bi1.add(bi2);

  }
}