Nakul P. Patel wrote:After sorting List in ascending and descending order i want to invoke binarySearch method. But it not working as i have implemented comparable.
Are you sure about that? It looks to me as though you're just not calling it properly.
It's probably also worth mentioning that if you're using Comparators, you have to invoke it with the same Comparator that was used to sort.
PS: Please UseCodeTags (←click) when you post code. I've added them for you this time - See how much better it looks?
K. Tsang wrote:Comparable returns a int -1, 0 or 1. Zero is equals, -1 if input1 is bigger, and 1 if input2 is bigger.
In your code, you should do a < or > comparison instead of the difference.
Not true. The return value is < 0, 0 or > 0. The < 0 doesn't have to be -1, and the > 0 doesn't have to be 1. Unless the subtraction leads to overflow, it's a valid implementation.