public class Demo4 {
public static void main(String[] args) {
Map<String, Student> map = new TreeMap<String, Student>(new Comparator<String>()
{
@Override
public int compare(String s1, String s2) {
return -1;
}
});
map.put("abc", new Student("1", "11"));
map.put("bac", new Student("2", "22"));
map.put("cba", new Student("3", "33"));
map.put("cab", new Student("4", "44"));
map.put("b", new Student("5", "55"));
map.put("a", new Student("5", "55"));
map.put("bca", new Student("6", "66"));
Set<String> set = map.keySet();
for (String key : set) {
Student s = map.get(key);
System.out.println(s.getName() + "***" + s.getId());
}
}
}
public class Student {
private String id;
private String name;
public Student() {
super();
}
public Student(String id, String name) {
super();
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Student [id=" + id + ", name=" + name + "]";
}
}
|