Originally posted by Raul Morales: ... Somebody could explain me why K & B test said that this order the collection in reverse order...
In a String, the indexing of characters starts at zero. So notice that the array is being sorted based on the second letter (charAt(1)) of each String. Here's the code with some lines added to show how the Comparator is working.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
The comparator arrange the strings in reverse order as s2[ind]-s1[ind] is being done.i.e when s2[ind] is 'b' and s1[ind] is 'a', then the compare method returns positive integer('b'-'a') saying 'b' > 'a'(reverse order).
And the character under concern is of index 1.so the order '0'>'g'>'a'. Otherwise - Good>Ugly>bad.
Hope this is clear.
Regards,<br />RAMESH VARDHAN.
Joined: Jun 21, 2005
For the purpose of explanation i used s2[ind] instead of s2.charAt(ind).
Please do not confuse.Sorry if I have already created.