第274页 其中CustomComparator这个类应为
package
Collection.Sort;
import java.util.Comparator;
public class CustomComparator implements Comparator {
public int compare(Object o1, Object o2) {
String s1 = (String)o1;
String s2 = (String)o2;
if (s1.equals(s2)) {
return 0 ;
}
else if (s1.compareTo(s2) > 0 ) {
return - 1 ;
}
else {
return 1 ;
}
}
}
import java.util.Comparator;
public class CustomComparator implements Comparator {
public int compare(Object o1, Object o2) {
String s1 = (String)o1;
String s2 = (String)o2;
if (s1.equals(s2)) {
return 0 ;
}
else if (s1.compareTo(s2) > 0 ) {
return - 1 ;
}
else {
return 1 ;
}
}
}
s1.compareTo(s2)>0而非 s1.compareTo(s2)==1