从int值创建BigInteger实例的最有效方法是什么?

Rom*_*man 13 java biginteger

我有一个BigInteger参数的方法(在第三方库中):

public void setValue (BigInteger value) { ... }
Run Code Online (Sandbox Code Playgroud)

我不需要"全部力量",我只需要使用整数.那么,我如何将整数传递给这个方法呢?我的解决方案是从int值获取字符串值,然后从字符串创建BigInteger:

int i = 123;
setValue (new BigInteger ("" + i));
Run Code Online (Sandbox Code Playgroud)

还有其他(推荐)方法吗?

Boz*_*sov 8

使用静态方法BigInteger.valueOf(long number).int值将long自动提升.