File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes binarySearch() : Help Needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "binarySearch() : Help Needed" Watch "binarySearch() : Help Needed" New topic

binarySearch() : Help Needed

Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 392
At page 557 :

If the collection/array you want to search was sorted using a Comparator, it must be searched using the same Comparator, which is passed as the second argument to the binarySearch() method. Remember that Comparators cannot be used when searching arrays of primitives.

Is comparator 2nd or 3rd argument to binarySearch() ?
Allan Jacobs

Joined: Aug 28, 2006
Posts: 15
Third argument.

Simple API questions are answerable using the Javadoc for the Java API at The signature for the binarySearch
that takes a comparator is:

static <T> int binarySearch(T[] a, T key, Comparator<? super T> c)
I agree. Here's the link:
subject: binarySearch() : Help Needed
It's not a secret anymore!