For binary search to work correctly in Java, the collection must be sorted using the same ordering (natural or comparator) that will be used for the search. If you sort with one comparator and search with another, binarySearch() behavior is undefined and results will be incorrect.