1
import java.util.*;
public class CW3 {
private static HashMap < String, Integer > map = new HashMap < String, Integer >();
int comp(String s1, String s2) {
int i1 = map.get(s1);
int i2 = map.get(s2);
if (i1 < i2)
return -1 ;
else if (i1 == i2)
return 0;
else
return 1;
}
void sort(List l) {
Comparator c = new Comparator() {
public int compare(Object o1,Object o2) {
String a = (String)o1;
String b = (String)o2;
int result = new CW3().comp(a,b);
return result;
}
};
// this is where I need help
}
}
如何使用比較器對列表進行排序?使用比較器對列表進行排序
我正沿着Collections.sort的線想,也許事情(L,C)