开发者

What is the most effective way to create BigInteger instance from int value?

开发者 https://www.devze.com 2022-12-27 04:43 出处:网络
I have a m开发者_运维问答ethod (in 3rd-party library) with BigInteger parameter: public void setValue (BigInteger value) { ... }

I have a m开发者_运维问答ethod (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?


BigInteger.valueOf(i);


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


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


setValue(BigInteger.valueOf(123L));
0

精彩评论

暂无评论...
验证码 换一张
取 消