HashSet API

  • 和map的区别,只有一个东西。

  • 很多都是用map的api完成,只是不用到的就取消了

Important point reated to HashSet:

API 1: add(E a)

  • adds the specified element to this set if this set contains no element return true

  • 如果set 里面有这个element就不会加了

API 2: clear()

API 3: clone()

API 4: contains(Object o)

API 5: isEmpty()

API 6: remove(Object o)

API 7: size()

API 8: toArray()

API 9: iterator()

public static void main(String[] args) {
    Set<String>
}

for (Type eachElement: set)

Last updated