[英]using java default binarysearch on biginteger
我在BigInteger
數組上使用了binarySearch ,我測試了幾個數字,似乎工作正常。 所以我假設我不需要實現/覆蓋任何方法(例如Comparator)才能正常工作?
我正在使用以下方法:
static int binarySearch(Object[] a, Object key)
//Searches the specified array for the specified object using the binary search algorithm.
像這樣:
int i = Arrays.binarySearch(arrayOfBigIntsPreDefined,new BigInteger("1111111111111111"));
如果有更好/適當/眾所周知的方法,請同時建議。
BigInteger
已經實現了Comparable<BigInteger>
,因此無需傳入自己的Comparator
(除非您出於某種原因決定重新定義兩個BigInteger
的比較方式)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.