public class IntSet
extends java.lang.Object
Class IntSet represents an indexed set of integers.
Class IntSet is not thread-safe.
| Constructor and Description |
|---|
IntSet(int capacity)
Creates a new
IntSet instance. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(int element)
Adds the specified element to this set.
|
int |
capacity()
Returns the capacity of this set.
|
void |
clear()
Removes all elements from this set.
|
boolean |
contains(int element)
Returns
true if the set contains the specified element,
and returns false otherwise. |
int |
elementWithIndex(int index)
Returns the specified element.
|
boolean |
remove(int element)
Removes the specified element from this set.
|
void |
setCapacity(int capacity)
Sets the capacity of this list to the specified value.
|
int |
size()
Returns the number of elements in this set.
|
int[] |
toArray()
Returns an array containing the elements in this set.
|
java.lang.String |
toString()
Returns
java.util.Arrays.toString(this.toArray()). |
public IntSet(int capacity)
IntSet instance.capacity - the initial capacity of the setjava.lang.IllegalArgumentException - if
capacity < 0 || (capacity > (1 << 30))public boolean contains(int element)
true if the set contains the specified element,
and returns false otherwise.element - an nonnegative integertrue if the set contains the specified elementpublic boolean add(int element)
element - an integer to add to this settrue if the set was changed by the operation, and
false otherwisepublic boolean remove(int element)
element - an integer to remove this settrue if the set was changed by the operation, and
false otherwisepublic int elementWithIndex(int index)
index - an index of an element in this setjava.lang.IndexOutOfBoundsException - if
index < 0 || index >= this.size()public void clear()
public int size()
public int capacity()
public void setCapacity(int capacity)
capacity - the desired capacityjava.lang.IllegalArgumentException - if capacity < this.size()public int[] toArray()
this.toArray()[j]==this.elementWithIndex(j) for each
j satisfying 0 < j && j < this.size()public java.lang.String toString()
java.util.Arrays.toString(this.toArray()).toString in class java.lang.Objectjava.util.Arrays.toString(this.toArray())