【发布时间】:2019-02-02 15:02:17
【问题描述】:
【问题讨论】:
【问题讨论】:
HashMap 和 HashSet 不是排序集合,因此没有构造函数来获取 Comparator。相反,您必须使用TreeSet 或TreeMap,其中包含一个重载的构造函数来接收Comparator。所以代码应该这样更正。
Map<Student, String> empMap = new TreeMap<>(new MyCustComparator());
Set<Student> set = new TreeSet<>(new MyCustComparator());
【讨论】: