Package ints
Class SynchedIntList
- java.lang.Object
-
- ints.SynchedIntList
-
public class SynchedIntList extends java.lang.ObjectClass
SynchedIntListrepresents a list of integers. ClassSynchedIntListsupports aclear()method, but it does not support aremove()method.Instances of class
SynchedIntListare thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_INIT_CAPACITYThe default initial capacity of anSynchedIntList, which is 16.
-
Constructor Summary
Constructors Constructor Description SynchedIntList()Constructs 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(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.java.lang.StringtoString()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 anSynchedIntListobject with the default initial capacity.- See Also:
DEFAULT_INIT_CAPACITY
-
SynchedIntList
public SynchedIntList(int initCapacity)
Constructs anSynchedIntListobject 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 anSynchedIntListby cloning the specified array.- Parameters:
ia- a list of integer values- Throws:
java.lang.NullPointerException- ifia == null
-
SynchedIntList
public SynchedIntList(SynchedIntList intList)
Constructs anSynchedIntListby 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:
toStringin classjava.lang.Object- Returns:
java.util.Arrays.toString(this.toArray())
-
-