E
- the type of elements maintained by this setpublic class WeakSet<E> extends AbstractSet<E> implements Cloneable, Serializable
Constructor and Description |
---|
WeakSet()
Constructs a new, empty WeakSet with the default initial
capacity (16) and load factor (0.75).
|
WeakSet(Collection<? extends E> s)
Constructs a new WeakSet with the same mappings as the
specified map.
|
WeakSet(int initialCapacity)
Constructs a new, empty WeakSet with the given initial
capacity and the default load factor (0.75).
|
WeakSet(int initialCapacity,
float loadFactor)
Constructs a new, empty WeakSet with the given initial
capacity and the given load factor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e) |
void |
clear() |
Object |
clone() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
boolean |
equals(Object o) |
int |
hashCode() |
boolean |
isEmpty() |
Iterator<E> |
iterator() |
E |
putIfAbsent(E e)
Put object in this set if equal one is not yet in set.
|
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
void |
resize(int newCapacity)
compact set if it is empty by setting new capacity
|
boolean |
retainAll(Collection<?> c) |
int |
size() |
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
String |
toString() |
addAll
finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, spliterator
parallelStream, removeIf, stream
public WeakSet(int initialCapacity, float loadFactor)
initialCapacity
- The initial capacity of the WeakSetloadFactor
- The load factor of the WeakSetIllegalArgumentException
- if the initial capacity is negative,
or if the load factor is nonpositive.public WeakSet(int initialCapacity)
initialCapacity
- The initial capacity of the WeakSetIllegalArgumentException
- if the initial capacity is negativepublic WeakSet()
public WeakSet(Collection<? extends E> s)
s
- the map whose mappings are to be placed in this mapNullPointerException
- if the specified map is nullpublic void clear()
clear
in interface Collection<E>
clear
in interface Set<E>
clear
in class AbstractCollection<E>
public int size()
size
in interface Collection<E>
size
in interface Set<E>
size
in class AbstractCollection<E>
public boolean isEmpty()
isEmpty
in interface Collection<E>
isEmpty
in interface Set<E>
isEmpty
in class AbstractCollection<E>
public boolean contains(Object o)
contains
in interface Collection<E>
contains
in interface Set<E>
contains
in class AbstractCollection<E>
public boolean remove(Object o)
remove
in interface Collection<E>
remove
in interface Set<E>
remove
in class AbstractCollection<E>
public void resize(int newCapacity)
newCapacity
- new capacitypublic boolean add(E e)
add
in interface Collection<E>
add
in interface Set<E>
add
in class AbstractCollection<E>
WeakSet.putIfAbsent(E)
public Object[] toArray()
toArray
in interface Collection<E>
toArray
in interface Set<E>
toArray
in class AbstractCollection<E>
public <T> T[] toArray(T[] a)
toArray
in interface Collection<E>
toArray
in interface Set<E>
toArray
in class AbstractCollection<E>
public String toString()
toString
in class AbstractCollection<E>
public int hashCode()
hashCode
in interface Collection<E>
hashCode
in interface Set<E>
hashCode
in class AbstractSet<E>
public boolean equals(Object o)
equals
in interface Collection<E>
equals
in interface Set<E>
equals
in class AbstractSet<E>
public boolean containsAll(Collection<?> c)
containsAll
in interface Collection<E>
containsAll
in interface Set<E>
containsAll
in class AbstractCollection<E>
public boolean removeAll(Collection<?> c)
removeAll
in interface Collection<E>
removeAll
in interface Set<E>
removeAll
in class AbstractSet<E>
public boolean retainAll(Collection<?> c)
retainAll
in interface Collection<E>
retainAll
in interface Set<E>
retainAll
in class AbstractCollection<E>
public E putIfAbsent(E e)
WeakSet<MyClass> set = new WeakSet<MyClass>(); ... MyClass sharedValue = set.putIfAbsent(new MyClass("abc));
e
- object to put in set.