集合全概述、Collection-Set集合
Set是无序的,唯一的
HashSet
-
底层数据结构是哈希表(是一个元素为链表的数组)
-
如何保证元素唯一性?
- 哈希表底层依赖两个方法:hashCode()和equals()方法
-
HashSet保证元素唯一性的解析
- **add方法底层依赖两个方法:hashCode()和equals()方法

LinkedHashSet
TreeSet
- 底层数据结构是红黑树(是一个自平衡的二叉树)
- 能够对元素按照某种规则排序(按照自己实现的接口定义!)

TreeSet存储元素自然排序和唯一的图解
两个比较,相同的不存,小的放左边,大的放右边

Collection 集合总结


针对Collection集合,我们到底使用谁

在集合中常见的数据结构

集合全概述、Collection-Set集合
原文:https://www.cnblogs.com/hellokaid/p/14620234.html