Hi
This is my own program and i wrote this program depending up on example in K & B book [p/g 566].I could not understand that program and i tried that using
String.
This is how i thought
o1<o2 returns -ve value
o1==o2 returns 0
o1>o2 returns +ve
import java.util.*;
import static java.lang.System.out;
class comp implements Comparator
{
public int compare(Object o1,Object o2)
{
String s1=(String)o1;
String s2=(String)o2;
return s2.charAt(1)-s1.charAt(1);//line 1
}
}
class Main3
{
public static void main(String... args)
{
String[] a={"anil","lalam","kumar"};
for(String s:a)
out.print(""+s);
out.println("\n\n");
Arrays.sort(a,new comp());
for(String s:a)
out.println("After :"+s);
}
}
How this working as reverse order?
Can any body explain me ?
Thanks
Anil Kumar