If the collection/array you want to search was sorted in natural order, it must be searched in natural order. (This is accomplished by NOT sending a Comparator as an argument to the binarySearch() method.
Why can't you send a Comparator argument? AFAIK, there's no reason why you can't use a comparator to sort/search in naturual order (even if doing that makes little sense).
We're binary code: a one and a zero<br />You wanted violins and you got Nero
Originally posted by John Meyers: Yep ! but nobody would do it
There are lots of things on the test that I can't imagine anyone doing (e.g. Integer Integer = new Integer()), but the quoted paragraph, to me, implies that it cannot be accomplished using a comparator, or that it's illegal to use a comparator.
If it's never tested, then no harm, no foul. Otherwise, I think Bert and Kathy should reword it.
I think the wording is accurate, but could perhaps be expanded on a bit. (I don't have the book, but I'm curious whether there's more context.)
As you've noted, the idea is that the ordering scheme used by a binary search must match whatever ordering was used to sort the collection or array. If natural ordering was used, then there's no need to provide a Comparator to the search method, although you could provide a natural-ordering Comparator.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org