I want to perform search operation on List of objects.The sorting of ascending and descending is working fine facing exception in implementation of binarySearch()
I am preparing for OCPJP. Please let me know briefly(if possible) where i am making mistake.
Nakul P. Patel wrote:Before doing search on list, the list must be sorted.Does it matter which one list i am using to search?
I think so. Because the returned index will be different. Look for 2 in natural order list gives the index 1 assuming it's 0-based. Same search in reverse order list gives second to last index, if 10 items indexed 0 to 9, it will return 8.
If you plan to use the 3 parm method, then pass in the a "comparator" not a Student.