You can refer to
java API documentation
That
doc says following things
I expalin with your code in short
public int compare(String s1,String s2)
{
return s2.charAt(1)-s1.charAt(1);
}
comparator sorts objects according to the values return by compare method that are 1, 0 and -1
when s1-s2 results 1 then s1 is greater than s2
when s1-s2 results 0 then s1 and s2 are equal
when s1-s2 results -1 then s1 is less than s2
And masre exam code is doing s2-s1 in compare method if this is the case then comparator is sorting objects in descending order
I hope this clears to you and inform me if I am wrong in somewhere in my explaination