HashSet:数据进行hashCode比较,然后进行equals方法比较,根据比较结果进行排序。如果要对对象进行排序,对象类要重写hashCode和equals方法。
HashMap:如果要对对象进行排序,对象类要重写hashCode和equals方法。
对象类重写hashCode与equals方法:对象类右键source(ALT+SHIFT+S)-Generate hashSet and equals().
TreeSet:如果要对对象进行排序,对象类要实现Comparable接口!
TreeMap:如果要对对象进行排序,对象类要实现Comparable接口!
TreeSet:如果要对对象进行排序,对象类要实现Comparable接口!
TreeMap:如果要对对象进行排序,对象类要实现Comparable接口!
对象里实现Comparable:对象类名+ implements Comparable(实现comparable接口).+comparaTo()方法