Package ints
Class SynchedIntList
- java.lang.Object
-
- ints.SynchedIntList
-
public class SynchedIntList extends java.lang.Object
Class
SynchedIntList
represents a list of integers. ClassSynchedIntList
supports aclear()
method, but it does not support aremove()
method.Instances of class
SynchedIntList
are thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_INIT_CAPACITY
The default initial capacity of anSynchedIntList
, which is 16.
-
Constructor Summary
Constructors Constructor Description SynchedIntList()
Constructs anSynchedIntList
object with the default initial capacity.SynchedIntList(int initCapacity)
Constructs anSynchedIntList
object with the specified initial capacity.SynchedIntList(int[] ia)
Constructs anSynchedIntList
by cloning the specified array.SynchedIntList(SynchedIntList intList)
Constructs anSynchedIntList
by copying the specifiedSynchedIntList
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int value)
Adds the specified integer to the end of this list.void
clear()
Removes all elements from this list.int
get(int index)
Returns the element at the specified position in this list.int
set(int index, int value)
Replaces the element at the specified position in this list with the specified element.int
size()
Returns the number of elements in this list.int[]
toArray()
Returns an integer array containing the sequence of elements in this list.java.lang.String
toString()
Returnsjava.util.Arrays.toString(this.toArray())
-
-
-
Field Detail
-
DEFAULT_INIT_CAPACITY
public static final int DEFAULT_INIT_CAPACITY
The default initial capacity of anSynchedIntList
, which is 16.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SynchedIntList
public SynchedIntList()
Constructs anSynchedIntList
object with the default initial capacity.- See Also:
DEFAULT_INIT_CAPACITY
-
SynchedIntList
public SynchedIntList(int initCapacity)
Constructs anSynchedIntList
object with the specified initial capacity.- Parameters:
initCapacity
- the initial capacity of this list- Throws:
java.lang.IllegalArgumentException
- ifinitCapacity < 0
-
SynchedIntList
public SynchedIntList(int[] ia)
Constructs anSynchedIntList
by cloning the specified array.- Parameters:
ia
- a list of integer values- Throws:
java.lang.NullPointerException
- ifia == null
-
SynchedIntList
public SynchedIntList(SynchedIntList intList)
Constructs anSynchedIntList
by copying the specifiedSynchedIntList
.- Parameters:
intList
- a list of integer values- Throws:
java.lang.NullPointerException
- ifintList == null
-
-
Method Detail
-
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:
java.lang.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:
java.lang.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
public java.lang.String toString()
Returnsjava.util.Arrays.toString(this.toArray())
- Overrides:
toString
in classjava.lang.Object
- Returns:
java.util.Arrays.toString(this.toArray())
-
-