gistfile1.txt package day18;import java.util.Comparator;import java.util.TreeMap;/** * 描述: * TreeMap集合键是Student值是String的案例 * * @outhor 71948 * @create 2017-10-06 22:37 */public class Demo7_TreeMap { public static void
package day18; import java.util.Comparator; import java.util.TreeMap; /** * 描述: * TreeMap集合键是Student值是String的案例 * * @outhor 71948 * @create 2017-10-06 22:37 */ public class Demo7_TreeMap { public static void main(String[] args) { TreeMaptm = new TreeMap<>(new Comparator () { @Override public int compare(Student o1, Student o2) { int num = o1.getName().compareTo(o2.getName()); return num == 0 ? o1.getAge()- o2.getAge() : num; } }); tm.put(new Student("卓胜达",21),"陆丰"); tm.put(new Student("datou",22),"中国"); System.out.println(tm); } public static void demo1(){ TreeMap tm = new TreeMap<>(); tm.put(new Student("zjhpng",12),"背景"); tm.put(new Student("z",12),"zsd"); System.out.println(tm); } }