集合Collection和Map结构原理

偏执的太偏执、 2022-03-19 13:54 402阅读 0赞














































































































































































































  List Set Map
AttributeofAll ArratList LinkedList Vector HashSet TreeSet LinkedHashSet HashMap HashTable LinkedHashMap TreeMap
数据结构 动态数组 链表结构,地址任意 动态数组 哈希表 二叉树 链表+哈希表 散列 散列 哈希表+链表 二叉树
优点 地址连续,索引速度快 新增删除新能好 实现同步,并发性好 addremovecontains方法 的时间复杂度为常量O(1) 元素是可排序 保留了元素插入顺序,时间复杂度为O(1) 定位元素时间复杂度平均能达到O(1) 同步 可预知迭代顺序 根据其键的自然顺序进行排序
缺点 新增||删除性能差 索引设计指针移动性能较差 同步会损失部分性能 元素是无序的 addremovecontains方法的时间复杂度为O(log(n)) 性能相对低 非同步 性能低   时间复杂度平均能达到O(log n)
是否同步 no no yes no no no no yes no no
可否重复 yes yes yes no no no yes yes yes yes
可否为null yes yes yes yes no no yes no yes yes
初始大小 10 10 16 16 16 16 11 16 16
扩容因子 0.5 无(链表结构直接往后面添加) 1 1 1 1 1 1+1 1 1
加载因子 1 1 0.75 0.75 0.75 0.75 0.75 0.75 0.75
                     
                     
                     
                     
                     

发表评论

表情:
评论列表 (有 0 条评论,402人围观)

还没有评论,来说两句吧...

相关阅读