public int compare(
String s1,String s2)
{
return s2.charAt(1)-s1.charAt(1);
}
In the code above, say s1="cat", and s2="dog".
The s2.charAt(1) = 'a' and s1.charAt(1)='o'.
Therefore compare() will return the int value of 'o'-'a'.
Note that compare() does not account for when s1 or s2 or both have length 1 or 0. It should have code to take care of these situations and also when either or both of them are null.