public class IntArraySet extends IntSet
(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... elements)
Add new elements to this set.
|
void |
add(IntSet set2)
Add to this set any element of another set that is not already in 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.
|
IntSet |
intersection(IntSet set2)
Create a new set that contains all the elements that are in both this set and the other set.
|
void |
keepCommonElements(IntSet set2)
Remove from this set any of its elements that are not contained in another set.
|
IntSet |
minus(IntSet 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 |
subtract(IntSet set2)
Remove from this set any element of another set that is in this set.
|
int[] |
toArray()
Create an array represntation of the contents of this set.
|
String |
toString()
Create a String representation of the contents of this set.
|
void |
trimToSize()
Reduce the current capacity of this set to its actual size
(i.e., the number of elements it contains).
|
IntSet |
union(IntSet set2)
Create a new set that contains all the elements from this set and the other set.
|
public IntArraySet()
OutOfMemoryError
- Indicates insufficient memory for:
new int[10].public IntArraySet(int initialCapacity)
initialCapacity
- the initial capacity of this setIllegalArgumentException
- Indicates that initialCapacity is negative.OutOfMemoryError
- Indicates insufficient memory for: new int[initialCapacity].public void add(int... elements)
public void add(IntSet set2)
public boolean contains(int target)
public void ensureCapacity(int minimumCapacity)
minimumCapacity
- the new capacity for this setOutOfMemoryError
- Indicates insufficient memory for: new int[minimumCapacity].public int getCapacity()
public IntSet intersection(IntSet set2)
intersection
in class IntSet
set2
- the second set in the intersectionpublic void keepCommonElements(IntSet set2)
keepCommonElements
in class IntSet
set2
- a set whose elements will be intersected with this setpublic IntSet minus(IntSet set2)
public boolean remove(int target)
public int size()
public void subtract(IntSet set2)
public int[] toArray()
public String toString()
public void trimToSize()
OutOfMemoryError
- Indicates insufficient memory for altering the capacity.