簡體   English   中英

在biginteger上使用java默認的binarysearch

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM