[英]Java - How to cast BigInteger set to BigInteger array
我有以下代碼:
public static BigInteger[] Cubes (int m){
Set<BigInteger> result = new HashSet<BigInteger>();
for (int i = 1;; i++){
BigInteger check = BigInteger.valueOf(i).pow(3);
if (String.valueOf(check).length() == m){
result.add(check);
}
if (String.valueOf(check).length() > m) break;
}
// I now have a BigInteger set containing all my values.
// I need to cast this to a BigInteger[] over here.
// Then, I can return a BigInteger array.
}
實現這一目標的最有效方法是什么?
您可以嘗試使用Java Collections toArray()方法 :
BigInteger[] output = result.toArray(new BigInteger[result.size()]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.