jose chiramal wrote:Looks like i would have to look into the "sort" method code under collections class to figure out the logic that is being used here, am I correct ?
You could. Or you could just pick up a book on algorithms, and just skim the code. To answer your question....
Yes, you are correct. How compare() or compareTo() methods are called totally depends on the sorting algorithm being used. For example, a bubble sort will call neighboring elments to determine if they should be swapped. Whereas a quick sort algorithm will do a "divide and conquer" approach. Etc. Etc. Etc.
And instead of looking into source to just see how it is done in
java, it may be better to understand the algorithm first (I believe the collections sort uses a combination of quick sort and heap sort as the algorithm). Sorting algorithms are generally covered in an university algorithms course, so there are tons of text books for it.
Henry