什么都不说了直接上代码
TreeSet<user> sortset = new TreeSet<test2.user>(new Comparator<user>() {
@Override
public int compare(user o1, user o2) {
if (o1.value < o2.value) {
return -1;
} else if (o1.value > o2.value) {
return 1;
} else {
return o1.name.compareTo(o2.name);
}
}
});
Iterator iterator = map.keySet().iterator();
while (iterator.hasNext()) {
String key = (String) iterator.next();
int value = (Integer) map.get(key);
user u = new user(key, value);
sortset.add(u);
}
|