views:

112

answers:

5

I have a method (in 3rd-party library) with BigInteger parameter:

public void setValue (BigInteger value) { ... }

I don't need 'all its power', I only need to work with integers. So, how can I pass integers to this method? My solution is to get string value from int value and then create BigInteger from string:

int i = 123;
setValue (new BigInteger ("" + i));

Are there any other (recommended) ways to do that?

+11  A: 
BigInteger.valueOf(i);
Michael Borgwardt
The winner. Yeah!!! :-)
Tadeusz Kopec
You won the race, congrats:)
Petar Minchev
Cool :) Didn't noticed that method myself.
Roman
All the numeric classes have it - Long, Integer...
Bozhidar Batsov
That was a fast answer
Nils Schmidt
I lost by a 6 seconds.. (I just made up that number).
Rosdi
+2  A: 

Use the static method BigInteger.valueOf(long number). int values will be promoted to long automatically.

Bozhidar Batsov
A: 
BigInteger.valueOf(i);
Rosdi
A: 

You can use this static method: BigInteger.valueOf(long val)

Petar Minchev
A: 

setValue(BigInteger.valueOf(123L);

Paul Croarkin