Iterable<E>, Collection<E>, Set<E>public final class LightweightSet<E> extends Object implements Collection<E>, Set<E>
Collection and Set interfaces.
The LightweightSet container uses less memory than the HashSet container,
but may show poor performance when reaching a large size.
It is recommended that you use this container when less memory is required.
Note: The thread is secure only when data is read from the LightweightSet container.
| 构造器 | 说明 |
|---|---|
LightweightSet() |
Constructs a default
LightweightSet container. |
LightweightSet(int capacity) |
Constructs an
LightweightSet container with a specified capacity. |
LightweightSet(int capacity,
boolean useIdentityHash) |
Constructs an
LightweightSet container with a specified capacity and
specifies whether to use the system hash method to map keys. |
LightweightSet(LightweightSet<? extends E> srcLightweightSet) |
Constructs a new
LightweightSet container using an existing LightweightSet container. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
boolean |
add(E element) |
Adds a specified
element object to an LightweightSet container. |
boolean |
addAll(Collection<? extends E> collection) |
Adds all objects in a specified
Collection to an LightweightSet container. |
boolean |
addAll(LightweightSet<? extends E> array) |
Adds all the objects in a specified
LightweightSet container to the current LightweightSet
container. |
void |
clear() |
Clears an
LightweightSet container. |
boolean |
contains(Object key) |
Checks whether an
LightweightSet container has a specified key. |
boolean |
containsAll(Collection<?> collection) |
Checks whether an
LightweightSet container has all the objects of a specified Collection. |
void |
ensureCapacity(int minimumCapacity) |
Ensures that the capacity of an
LightweightSet container is greater than or equal to a specified value,
and that the container has all the original objects after capacity expansion. |
boolean |
equals(Object obj) |
Checks whether the objects of an
LightweightSet container are of the same type as a specified
Object. |
int |
hashCode() |
Obtains the hash value of an
LightweightSet container. |
int |
indexOf(Object key) |
Obtains the index of a
key of a specified Object type in an LightweightSet container. |
boolean |
isEmpty() |
Checks whether an
LightweightSet container has no object. |
Iterator<E> |
iterator() |
Obtains an
Iterator that can operate the LightweightSet container. |
boolean |
remove(Object obj) |
Deletes an object of a specified
Object type from an LightweightSet container. |
boolean |
removeAll(Collection<?> collection) |
Deletes all the objects that are contained in a specified
Collection from an LightweightSet
container. |
boolean |
removeAll(LightweightSet<? extends E> array) |
Deletes all the objects that are contained in a specified
LightweightSet container
from an LightweightSet container. |
E |
removeAt(int index) |
Deletes an object at the location identified by
index from an LightweightSet container. |
boolean |
retainAll(Collection<?> collection) |
Deletes the objects that do not exist in a specified
Collection from an LightweightSet container. |
int |
size() |
Obtains the number of objects in an
LightweightSet container. |
Object[] |
toArray() |
Obtains an array that contains all the objects of an
LightweightSet container. |
<T> T[] |
toArray(T[] array) |
Obtains an array that contains all the objects of an
LightweightSet container. |
String |
toString() |
Obtains a string that contains all the objects of an
LightweightSet container. |
E |
valueAt(int index) |
Obtains the object at the location identified by
index in an LightweightSet container. |
E |
valueAt(int index,
E defaultKey) |
Obtains the object at the location identified by
index in an LightweightSet container. |
parallelStream, removeIf, streamspliteratorpublic LightweightSet()
LightweightSet container.public LightweightSet(int capacity)
LightweightSet container with a specified capacity.capacity - Indicates the capacity of the LightweightSet container to be constructed.public LightweightSet(int capacity,
boolean useIdentityHash)
LightweightSet container with a specified capacity and
specifies whether to use the system hash method to map keys.capacity - Indicates the capacity of the LightweightSet container to be constructed.useIdentityHash - Specifies whether the system hash method is used to map keys.
The value true indicates that the System.identityHashCode method is used.
The value false indicates that the default hashCode method is used.public LightweightSet(LightweightSet<? extends E> srcLightweightSet)
LightweightSet container using an existing LightweightSet container.srcLightweightSet - Indicates an existing LightweightSet container.public boolean add(E element)
element object to an LightweightSet container.public boolean addAll(LightweightSet<? extends E> array)
LightweightSet container to the current LightweightSet
container.
Before the objects are added, the capacity of the current LightweightSet container
will be checked and assured.
array - Indicates the specified LightweightSet container whose objects are to be added
to the current LightweightSet container.true if any object is added to the current container;
returns false otherwise.NullPointerException - Throws this exception if array is null.public boolean addAll(Collection<? extends E> collection)
Collection to an LightweightSet container.addAll 在接口中 Collection<E>addAll 在接口中 Set<E>collection - Indicates the Collection whose objects are
to be added to the LightweightSet container.true if any object is added to the container; returns false otherwise.NullPointerException - Throws this exception if collection is null.Collection.add(Object)public void clear()
LightweightSet container.
This method makes the LightweightSet container empty.
public boolean contains(Object key)
LightweightSet container has a specified key.public boolean containsAll(Collection<?> collection)
LightweightSet container has all the objects of a specified Collection.containsAll 在接口中 Collection<E>containsAll 在接口中 Set<E>collection - Indicates the specified Collection.true if the LightweightSet container has all the objects
of the specified Collection;
returns false otherwise.NullPointerException - Throws this exception if collection is null.Collection.contains(Object)public void ensureCapacity(int minimumCapacity)
LightweightSet container is greater than or equal to a specified value,
and that the container has all the original objects after capacity expansion.minimumCapacity - Indicates the minimum capacity allowed for the LightweightSet container.public boolean equals(Object obj)
LightweightSet container are of the same type as a specified
Object.equals 在接口中 Collection<E>equals 在接口中 Set<E>equals 在类中 Objectobj - Indicates the Object to be compared with the objects of the LightweightSet container.true if the objects of the LightweightSet container are of the same type
as the specified Object;
returns false otherwise.Object.hashCode(),
HashMappublic int hashCode()
LightweightSet container.
The hash value is the sum of the hash values of all objects of the LightweightSet container.
If the LightweightSet container has no object, the hash value is 0.
hashCode 在接口中 Collection<E>hashCode 在接口中 Set<E>hashCode 在类中 ObjectLightweightSet container.Object.equals(java.lang.Object),
System.identityHashCode(java.lang.Object)public int indexOf(Object key)
key of a specified Object type in an LightweightSet container.key - Indicates the key of a specified Object type.key in int format.public boolean isEmpty()
LightweightSet container has no object.public Iterator<E> iterator()
Iterator that can operate the LightweightSet container.public boolean remove(Object obj)
Object type from an LightweightSet container.public boolean removeAll(LightweightSet<? extends E> array)
LightweightSet container
from an LightweightSet container.array - Indicates the specified LightweightSet container.true if any object is deleted from the LightweightSet container;
returns false otherwise.NullPointerException - Throws this exception if array is null.public boolean removeAll(Collection<?> collection)
Collection from an LightweightSet
container.removeAll 在接口中 Collection<E>removeAll 在接口中 Set<E>collection - Indicates the specified Collection.true if any object is deleted from the LightweightSet container;
returns false otherwise.Collection.remove(Object),
Collection.contains(Object)public E removeAt(int index)
index from an LightweightSet container.
If index is a negative number, the object is located from the reverse direction.
During the deletion, the system determines whether to expand or reduce capacity
of the LightweightSet container. If the number of objects in the container is less
than a specified number, the system reduces the capacity of the container.
index - Identifies the location of an object.index.public boolean retainAll(Collection<?> collection)
Collection from an LightweightSet container.retainAll 在接口中 Collection<E>retainAll 在接口中 Set<E>collection - Indicates the specified Collection.true if any object is deleted from the LightweightSet container;
returns false otherwise.NullPointerException - Throws this exception if collection is null.Collection.remove(Object),
Collection.contains(Object)public String toString()
LightweightSet container.
An example string is "{1, 2}".
Objects in the LightweightSet container must support the toString method.
public int size()
LightweightSet container.public Object[] toArray()
LightweightSet container.public <T> T[] toArray(T[] array)
LightweightSet container.
If the capacity of the input array is insufficient, a new array with sufficient capacity will be used.
toArray 在接口中 Collection<E>toArray 在接口中 Set<E>T - the runtime type of the array to contain the collectionarray - Indicates the array that stores all objects of the LightweightSet container.LightweightSet container.NullPointerException - Throws this exception if array is null.public E valueAt(int index)
index in an LightweightSet container.
If index is a negative number, the object is located from the reverse direction.
index - Identifies the location of an object.index in the LightweightSet container.public E valueAt(int index, E defaultKey)
index in an LightweightSet container.
If index is a negative number, the object is located from the reverse direction.
If the index is invalid (for example, it is greater than the number of
objects in the LightweightSet container or less than 0), defaultKey will be returned.
index - Identifies the location of an object.defaultKey - Indicates the default value returned if the specified index is invalid.index in the LightweightSet container.