先上一张Java集合的框架图,便于参考
以下所有特性仅代表自JAVA 1.8
Set
interface Iterableinterface Collection extends Iterable interface Set extends Collection abstract AbstractCollection implements Collection abstract AbstractSet extends AbstractCollection implements Set
HashSet:
HashSet
1.使用HashMap
2.由于HashMap存储的数据是无序的,而Set是通过HashMap存储数据,因此Set存储的数据也是无序的
3.由于HashMap的 key 不能够重复, 因此HashSet 不能存储重复的数据,重复的数据会产生覆盖。
linkedHashSet:
linkedHashSet
1.使用linkedHashSet
2.由于linkedHashMap存储数据是有序的, 因此linkedHashSet也是有序的。
3.由于linkedHashMap的 key 不能够重复,会覆盖重复的内容, 因此linkedHashSet 也不能存储重复的数据。



