HashSet

Basics#

  • Implements Set

Construction#

  • with predefined value (might contain duplicates)
Set<Integer> set = new HashSet<>(Arrays.asList(1,1,1,2,2,3));

Methods#

MethodRuntimeDescriptionReturn Type
add(E e)O(log n)Appends the specified element to the end of this list.boolean
clear()O(n)removes all elementvoid
contains(Object o)O(n) worst timecontainsboolean
iterator()O(1)creates a iteratorIterator
offer(E e)O(log n)insert element (like add)boolean
peek()O(1)retreves the headE
poll()O(n)retrieves and remove the headE
remove(Object o)o(n)removes a single instance of the specified valueboolean
size()O(1)return the sizeint
toArray()/toArray(T[] a)O(n)return the array[]/ T[]