1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| package Day2.class2;
import java.util.Comparator; import java.util.Map; import java.util.TreeMap;
public class text { public static void main(String[] args) { TreeMap<student,String> p=new TreeMap<>(( o1, o2)-> { int i=o1.getAge()-o2.getAge(); i=i==0?o1.getName().compareTo(o2.getName()):i; return i; }); student s1=new student("zhan",17); student s2=new student("Li",13); student s3=new student("wanwu",13); student s4=new student("qiao",13); p.put(s1,"深圳"); p.put(s2,"北京"); p.put(s3,"上海"); p.put(s4,"广州"); for (Map.Entry<student, String> a : p.entrySet()) { System.out.println(a.getKey()); System.out.println(a.getValue()); } }
}
|