当前位置 : 主页 > 编程语言 > c++ >

TreeMap集合键是Student值是String的案例

来源:互联网 收集:自由互联 发布时间:2021-06-30
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
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 main(String[] args) {
        TreeMap
 
   tm = 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); } }
   
  
 
网友评论