E - type of element in this setpublic class RemovableSingletonSet<E> extends AbstractSet<E>
Similar to Collections.singleton() but provides the ability to remove the single element and clear the set. Iterator supports remove() operations while maintaining singleton behavior.
Does not support add() or addAll() operations as they would violate the singleton contract. Item may not be null.
Useful for scenarios requiring a single, modifiable element with standard collection interface compliance and removal capabilities.
| Constructor and Description |
|---|
RemovableSingletonSet(E element)RemovableSingletonSet. |
| Modifier and Type | Method and Description |
|---|---|
void | clear()clear. |
boolean | contains(Object o)contains. |
boolean | isEmpty() |
Iterator<E> | iterator()iterator. |
boolean | remove(Object o)remove. |
int | size()size. |
equals, hashCode, removeAlladd, addAll, containsAll, retainAll, toArray, toArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitadd, addAll, containsAll, retainAll, spliterator, toArray, toArrayparallelStream, removeIf, streampublic RemovableSingletonSet(E element)
public void clear()
clear in interface Collection<E>clear in interface Set<E>clear 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 isEmpty()
isEmpty in interface Collection<E>isEmpty in interface Set<E>isEmpty 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 int size()
size in interface Collection<E>size in interface Set<E>size in class AbstractCollection<E>