Converting from Integer, to BigInteger

Steffan Harris picture Steffan Harris · Oct 7, 2010 · Viewed 228.3k times · Source

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 inconvertible type.

Answer

jbindel picture jbindel · Oct 7, 2010

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.