在biginteger上使用java默认二进制搜索
我使用了在biginteger上使用java默认二进制搜索,java,arrays,biginteger,binary-search,Java,Arrays,Biginteger,Binary Search,我使用了biginger的on数组,我使用了一些数字进行了测试,看起来效果不错。因此,我假设我不需要实现/覆盖任何方法(例如,比较器),它才能正常工作 我使用以下方法: static int binarySearch(Object[] a, Object key) //Searches the specified array for the specified object using the binary search algorithm. 像这样: int i = Arrays.bin
biginger
的on数组,我使用了一些数字进行了测试,看起来效果不错。因此,我假设我不需要实现/覆盖任何方法(例如,比较器),它才能正常工作
我使用以下方法:
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"));
如果有更好的/合适的/众所周知的方法,请也提出建议。
biginger
已经实现了Comparable
,所以没有必要传入您自己的比较器
(除非您出于某种原因决定重新定义两个biginger
的比较方式)。所以,让我把这个问题弄清楚。它适合你。没有性能问题。你为什么又问这个问题?@AdamGent她要求确认这种方法和其他可能更好的方法。@javadba我并不是想对此大惊小怪,只是我不知道该怎么假设。例如,我假设OP知道必须对数组进行排序。我也需要解释一下吗?然而,我现在意识到,根据另一个答案,OP只是不知道BigInteger是一个可比的。