What's the difference between HashSet and Set?

前端 未结 8 2034
独厮守ぢ
独厮守ぢ 2020-12-12 19:01

Saw the code snippet like

Set instances = new HashSet();

I am wondering if Hashset is a special kind of set. A

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 19:31

    **

    • Set:

    ** It is an interface which is a subtype of Collection interface, just like LIST and QUEUE.

    Set has below 3 subclasses, it is used to store multiple objects without duplicates.

    1. HashSet
    2. LinkedHashSet
    3. TreeSet(which implements SortedSet interface)

    **

    • HashSet:

    **

    Can use one NULL value(as Duplicate is not allowed), data is stored randomly as it does not maintain sequence.

提交回复
热议问题