1

我在数组上使用了binarySearchBigInteger,我用几个数字进行了测试,似乎工作正常。所以我假设我不需要实现/覆盖任何方法(例如比较器)就可以正常工作?

我正在使用以下方法:

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"));

如果有更好/合适/众所周知的方法,也请提出建议。

4

1 回答 1

3

BigInteger已经实现Comparable<BigInteger>,因此无需传入您自己的Comparator(除非您出于某种原因决定重新定义如何BigInteger比较两者)。

于 2013-04-13T19:47:12.300 回答