posted 13 years ago
Hi Sajjad,
Collections.binarySearch() requires that 1) either elements in the List implement Comparable and are mutually Comparable, or 2) provide a Comparator.
Your original error is because Student is not implementing Comparable.
It also requires that the List be sorted before searching, which you haven't done. That's because binary search algorithm is like that: Divide the list into 2 halves, see which half the element falls in, then divide that half into 2 halves, see which half.....and so on.
Why is equals not sufficient? Because when it divides the list into two, it needs to know in which half - lower or upper - the searched element belongs. equals alone can't tell that.
Cheers
Karthik