19

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?

Roman
  • 64,384
  • 92
  • 238
  • 332

4 Answers4

52
BigInteger.valueOf(i);
Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
8

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

Joey
  • 344,408
  • 85
  • 689
  • 683
Bozhidar Batsov
  • 55,802
  • 13
  • 100
  • 117
4

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

Petar Minchev
  • 46,889
  • 11
  • 103
  • 119
3
setValue(BigInteger.valueOf(123L));
Toby Speight
  • 27,591
  • 48
  • 66
  • 103
Paul Croarkin
  • 14,496
  • 14
  • 79
  • 118