TreeMap定制排序和自然排序自然排序是实现Comparable接口的方法.代码如下: @Override public int compareTo(Object o) { if (o instanceof Person){ Person p = (Person) o; int i= this.age.compareTo(p.age); if (i == 0){ return this.name.compareTo(p.name); }else { return i; } } return 0…
Java代码 import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.TreeMap; public class Test { public static void main(String[] args) { Map tree = new TreeMap(); Map linked = new LinkedHashMap(); Map hash = new …