Collections.sort(List<Object>, new Comparator<Object>() { public int compare(Object o1, Object o2) { return o1.getSort().compareTo(o2.getSort()); } }); Collections.sort(articles, new Comparator<Article>() { public int compare(Article kf1…
package cn.learn.collection.Collections; /* 排序的对象的类,实现comparable借口,重写compareto方法 若要打印必须重写toString方法,会默认调用 */ public class Person implements Comparable<Person>{ private String name; private int age; @Override public String toString() { return "P…
一.概述 程序要对一堆数据元素排序,查找,增加删除.数据节点 class Node{ int type; int index; int score; } 规则: 1)对象相等:两个节点n1与n2,如果n1.type == n2.type && n1.index == n2.index则n1等于n2 2)排序:升序,比较score,score相同则比较type,type相同则比较index.最开始我使用TreeMap存储.实现Comparable接口,重写equals方法与hashCode方…