Converting from Integer, to BigInteger

前端 未结 2 1505
猫巷女王i
猫巷女王i 2020-12-07 21:30

I was wondering if there was any way to convert a variable of type Integer, to BigInteger. I tried typecasting the Integer variable, but i get an error that says inconvertib

相关标签:
2条回答
  • 2020-12-07 21:57

    The method you want is BigInteger#valueOf(long val).

    E.g.,

    BigInteger bi = BigInteger.valueOf(myInteger.intValue());
    

    Making a String first is unnecessary and undesired.

    0 讨论(0)
  • 2020-12-07 21:57

    You can do in this way:

        Integer i = 1;
        new BigInteger("" + i);
    
    0 讨论(0)
提交回复
热议问题