【发布时间】:2014-05-10 15:52:47
【问题描述】:
我有 BigInt
BigInteger i = new BigInteger("5876934265987526278534978564378568734564937563487564327564376534875483753475");
我需要将其转换为[] int。我怎样才能快速做到这一点?
我的方法很慢
private static int[] convertDigitsToIntArray(java.math.BigInteger x) {
String s = x.toString();
int[] result = new int[s.length()];
for (int i = 0; i < s.length(); i++) {
result[i] = Integer.parseInt(String.valueOf(s.charAt(i)));
}
return result;
}
【问题讨论】:
-
你必须使用
Notepad++或EditPadPro并使用宏。我认为你不需要在这里编程。你需要定期录制宏并运行它。 -
调用
toString(),然后将每个字符转换为int?toString的优化可能相当好。 -
@Alan Stokes 方法太慢了。
-
如果 bigint 是
new BigInteger("-123"),你的结果 int[] 会是什么 -
我没有负值。
标签: java biginteger