public class IntArraySet
extends java.lang.Object
implements java.lang.Cloneable
(2) A set's capacity cannot exceed the maximum integer 2,147,483,647 (Integer.MAX_VALUE). Any attempt to create a larger capacity results in a failure due to an arithmetic overflow.
(3) Because of the slow linear algorithms of this class, large sets will have poor performance.
Constructor and Description |
---|
IntArraySet()
Initialize an empty set with an initial capacity of 10.
|
IntArraySet(int initialCapacity)
Initialize an empty set with a specified initial capacity.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int element)
Add a new element to this set.
|
void |
addAll(IntArraySet set2)
Add to this set any element of another set that is not already in this set.
|
void |
addMany(int... elements)
Add new elements to this set.
|
IntArraySet |
clone()
Generate a copy of this set.
|
boolean |
contains(int target)
Method to determine if a particular element
is in this set.
|
void |
ensureCapacity(int minimumCapacity)
Change the current capacity of this set.
|
int |
getCapacity()
Accessor method to get the current capacity of this set.
|
IntArraySet |
intersection(IntArraySet set2)
Create a new set that contains all the elements that are in both this set and one other set.
|
void |
keepCommonElements(IntArraySet set2)
Remove from this set any of its elements that are not contained in another set.
|
IntArraySet |
minus(IntArraySet set2)
Create a new set that contains all the elements from this set except those from the other set.
|
boolean |
remove(int target)
Remove a specified element from this set.
|
int |
size()
Determine the number of elements in this set.
|
void |
subtractAll(IntArraySet set2)
Remove from this set any element of another set that is in this set.
|
void |
trimToSize()
Reduce the current capacity of this set to its actual size (i.e., the
number of elements it contains).
|
IntArraySet |
union(IntArraySet set2)
Create a new set that contains all the elements from this set and one other set.
|
public IntArraySet()
-
- nonejava.lang.OutOfMemoryError
- Indicates insufficient memory for:
new int[10].public IntArraySet(int initialCapacity)
initialCapacity
- the initial capacity of this setjava.lang.IllegalArgumentException
- Indicates that initialCapacity is negative.java.lang.OutOfMemoryError
- Indicates insufficient memory for: new int[initialCapacity].public void add(int element)
element
- the new element that is being insertedjava.lang.OutOfMemoryError
- Indicates insufficient memory for increasing the set's capacity.public void addMany(int... elements)
elements
- (a variable-arity argument)
one or more new elements that are being insertedjava.lang.OutOfMemoryError
- Indicates insufficient memory for increasing the set's capacity.public void addAll(IntArraySet set2)
set2
- a set whose elements will be unioned with this setjava.lang.NullPointerException
- Indicates that set2 is null.java.lang.OutOfMemoryError
- Indicates insufficient memory to increase the size of this set.public void subtractAll(IntArraySet set2)
set2
- a set whose elements will be subtracted from this setjava.lang.NullPointerException
- Indicates that set2 is null.public void keepCommonElements(IntArraySet set2)
set2
- a set whose elements will be intersected with this setjava.lang.NullPointerException
- Indicates that set2 is null.public IntArraySet clone()
clone
in class java.lang.Object
-
- nonejava.lang.OutOfMemoryError
- Indicates insufficient memory for creating the clone.public boolean contains(int target)
target
- the element that needs to be found in this setpublic void ensureCapacity(int minimumCapacity)
minimumCapacity
- the new capacity for this setjava.lang.OutOfMemoryError
- Indicates insufficient memory for: new int[minimumCapacity].public int getCapacity()
-
- nonepublic boolean remove(int target)
target
- the element to be removed from the setpublic int size()
-
- nonepublic void trimToSize()
-
- nonejava.lang.OutOfMemoryError
- Indicates insufficient memory for altering the capacity.public IntArraySet union(IntArraySet set2)
set2
- the second set in the unionNullPointerException.
- Indicates that the argument is null.java.lang.OutOfMemoryError
- Indicates insufficient memory for the new set.public IntArraySet intersection(IntArraySet set2)
set2
- the second set in the intersectionNullPointerException.
- Indicates that the argument is null.java.lang.OutOfMemoryError
- Indicates insufficient memory for the new set.public IntArraySet minus(IntArraySet set2)
set2
- the second set in the subtractionNullPointerException.
- Indicates that the argument is null.java.lang.OutOfMemoryError
- Indicates insufficient memory for the new set.