public final class LongHashSet extends AbstractLongSet implements Cloneable, Serializable
LongSet interface, backed by a hash table
(actually a LongHashMap instance). It makes no guarantees as to the
iteration order of the set; in particular, it does not guarantee that the
order will remain constant over time.
Note that this implementation is not synchronized. If multiple
threads access a set concurrently, and at least one of the threads modifies
the set, it must be synchronized externally. This is typically
accomplished by synchronizing on some object that naturally encapsulates
the set. If no such object exists, the set should be "wrapped" using the
Collections.synchronizedSet(java.util.Set<T>) method. This is best done
at creation time, to prevent accidental unsynchronized access to the set.
The iterators returned by this class's iterator method are
fail-fast: if the set is modified at any time after the iterator is
created, in any way except through the iterator's own remove
method, the Iterator throws a ConcurrentModificationException.
Thus, in the face of concurrent modification, the iterator fails quickly
and cleanly, rather than risking arbitrary, non-deterministic behavior at
an undetermined time in the future.
| Constructor and Description |
|---|
LongHashSet()
Constructs a new, empty set.
|
LongHashSet(Collection<? extends Long> c)
Constructs a new set containing all elements from the specified
collection.
|
LongHashSet(int capacity)
Constructs a new set with a specified capacity.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(long key)
Ensures that this collection contains the specified element.
|
void |
clear() |
void |
clearAndCompact()
Removes all elements and frees all memory.
|
void |
clearAndCompact(int capacity)
Removes all elements and compacts memory usage of this hashtable,
but requested capacity is retained.
|
Object |
clone()
Returns a shallow copy of this set: the elements themselves are
not cloned.
|
void |
compact()
Compacts memory usage of this hashtable.
|
void |
compact(int capacity)
Compacts memory usage of this hashtable, but requested capacity
is retained.
|
boolean |
contains(long key)
Returns true if this collection contains the specified element.
|
void |
ensureCapacity(int capacity)
Makes sure that no rehashes or memory reallocations will be
needed until
size() <= capacity. |
boolean |
isEmpty() |
LongIterator |
longIterator()
Returns an iterator over the elements in this collection.
|
boolean |
remove(long key)
Removes a single instance of the specified element from this
collection, if it is present.
|
int |
size() |
add, addAll, contains, containsAll, iterator, remove, removeAll, retainAll, toLongArrayequals, hashCodetoArray, toArray, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitspliteratorlongStream, parallelLongStream, spliteratorparallelStream, removeIf, streampublic LongHashSet()
public LongHashSet(Collection<? extends Long> c)
public LongHashSet(int capacity)
public LongIterator longIterator()
LongCollectionlongIterator in interface LongCollectionlongIterator in class AbstractLongSetCollection.iterator()public int size()
size in interface Collection<Long>size in interface Set<Long>size in class AbstractLongSetpublic boolean isEmpty()
isEmpty in interface Collection<Long>isEmpty in interface Set<Long>isEmpty in class AbstractCollection<Long>public boolean contains(long key)
LongCollectioncontains in interface LongCollectioncontains in class AbstractLongSetCollection.contains(Object)public boolean add(long key)
LongCollectionadd in interface LongCollectionadd in class AbstractLongSetCollection.add(Object)public boolean remove(long key)
LongCollectionremove in interface LongCollectionremove in class AbstractLongSetCollection.remove(Object)public void clear()
clear in interface Collection<Long>clear in interface Set<Long>clear in class AbstractLongSetpublic Object clone()
public void ensureCapacity(int capacity)
size() <= capacity.LongHashMap.ensureCapacity(int)public void compact()
LongHashMap.compact()public void compact(int capacity)
public void clearAndCompact()
LongHashMap.clearAndCompact()public void clearAndCompact(int capacity)
LongHashMap.clearAndCompact(int)Copyright © 2002–2025 Devexperts LLC. All rights reserved.