treeset和hashset的區(qū)別 為什么TreeSet不需要覆寫equals和HashCode方法?
為什么TreeSet不需要覆寫equals和HashCode方法?Java采集框架的底層數(shù)據結構如下:ArrayList:array LinkedList:LinkedList TreeSet:bin
為什么TreeSet不需要覆寫equals和HashCode方法?
Java采集框架的底層數(shù)據結構如下:ArrayList:array LinkedList:LinkedList TreeSet:binary tree HashSet:hash table具有可比性,以comparator為比率,已知名稱,tree的所有底層數(shù)據結構都是二叉樹,而TreeSet set只需要在comparable中實現(xiàn)CompareTo方法,但只有當?shù)讓訑?shù)據結構是hash table時,才可以重寫equals和hashcode方法