Set和Map集合的比较

it2022-05-05  145

HashSet:数据进行hashCode比较,然后进行equals方法比较,根据比较结果进行排序。如果要对对象进行排序,对象类要重写hashCode和equals方法。 TreeSet:如果要对对象进行排序,对象类要实现Comparable接口! HashMap:如果要对对象进行排序,对象类要重写hashCode和equals方法。 TreeMap:如果要对对象进行排序,对象类要实现Comparable接口!

转载于:https://www.cnblogs.com/bpdxqx/p/5755341.html


最新回复(0)