Package ints
Class SynchedIntList
java.lang.Object
ints.SynchedIntList
Class SynchedIntList represents a list of integers.
Class SynchedIntList supports a clear() method,
but it does not support a remove() method.
Instances of class SynchedIntList are thread-safe.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default initial capacity of anSynchedIntList, which is 16. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs anSynchedIntListobject with the default initial capacity.SynchedIntList(int initCapacity) Constructs anSynchedIntListobject with the specified initial capacity.SynchedIntList(int[] ia) Constructs anSynchedIntListby cloning the specified array.SynchedIntList(SynchedIntList intList) Constructs anSynchedIntListby copying the specifiedSynchedIntList. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int value) Adds the specified integer to the end of this list.voidclear()Removes all elements from this list.intget(int index) Returns the element at the specified position in this list.intset(int index, int value) Replaces the element at the specified position in this list with the specified element.intsize()Returns the number of elements in this list.int[]toArray()Returns an integer array containing the sequence of elements in this list.toString()Returnsjava.util.Arrays.toString(this.toArray())
-
Field Details
-
DEFAULT_INIT_CAPACITY
public static final int DEFAULT_INIT_CAPACITYThe default initial capacity of anSynchedIntList, which is 16.- See Also:
-
-
Constructor Details
-
SynchedIntList
public SynchedIntList()Constructs anSynchedIntListobject with the default initial capacity.- See Also:
-
SynchedIntList
public SynchedIntList(int initCapacity) Constructs anSynchedIntListobject with the specified initial capacity.- Parameters:
initCapacity- the initial capacity of this list- Throws:
IllegalArgumentException- ifinitCapacity < 0
-
SynchedIntList
public SynchedIntList(int[] ia) Constructs anSynchedIntListby cloning the specified array.- Parameters:
ia- a list of integer values- Throws:
NullPointerException- ifia == null
-
SynchedIntList
Constructs anSynchedIntListby copying the specifiedSynchedIntList.- Parameters:
intList- a list of integer values- Throws:
NullPointerException- ifintList == null
-
-
Method Details
-
add
public void add(int value) Adds the specified integer to the end of this list.- Parameters:
value- the integer to be added to the end of this list
-
get
public int get(int index) Returns the element at the specified position in this list.- Parameters:
index- the index of the element to be returned- Returns:
- the element at the specified position in this list
- Throws:
IndexOutOfBoundsException- ifindex < 0 || index >= this.size()
-
set
public int set(int index, int value) Replaces the element at the specified position in this list with the specified element.- Parameters:
index- the index of the element to be replacedvalue- the value to be stored at the specified position in this list- Returns:
- the previous value at the specified position in this list
- Throws:
IndexOutOfBoundsException- ifindex < 0 || index >= this.size()
-
size
public int size()Returns the number of elements in this list.- Returns:
- the number of elements in this list
-
toArray
public int[] toArray()Returns an integer array containing the sequence of elements in this list.- Returns:
- an integer array containing the sequence of elements in this list
-
clear
public void clear()Removes all elements from this list. -
toString
Returnsjava.util.Arrays.toString(this.toArray())
-