Package com.iizix
Class IntArrayList
java.lang.Object
com.iizix.IntArrayList
Class mimicking the behavior of ArrayList with Integer without collection support.
This class is NOT thread safe.
- Author:
- Christopher Mindus
- Field SummaryFields
- Constructor SummaryConstructorsConstructorDescriptionCreates an array with an initial capacity of 16.- IntArrayList- (int size) Creates an array with an initial capacity.- IntArrayList- (int[] values) Creates an array with a set of values.- IntArrayList- (ArrayList<Integer> list) Creates an array from an ArrayList of Integer's.
- Method SummaryModifier and TypeMethodDescription- void- add- (int value) Adds a value to the end of the array.- void- add- (int index, int value) Adds a value to this list at the given index- void- addAll- (int[] values) Adds an array of values to the end of this array.- void- addAll- (IntArrayList list) Adds an array of values to the end of this array.- void- clear()Clears the array, i.e.- boolean- contains- (int value) Determines if this array contains a given value.- void- ensureCapacity- (int minCapacity) Ensures that this list's capacity is at list the given value.- int- get- (int index) Gets the value in the array at the given index.- int- indexOf- (int value) Finds the index of a value in this array.- int- instanceCount- (int value) Counts the number of times a value is represented in this array.- boolean- isEmpty()Checks if the array is empty.- int- lastIndexOf- (int value) Finds the index of a value in this array from the array's tail.- int- remove- (int index) Removes a value from this list- int- removeAll- (int value) Removes all instances of the given value from this array.- boolean- removeValue- (int value) Removes the first occurrence of a value from this array.- int- set- (int index, int value) Replaces a value in this list with another value.- int- size()Returns the size of the array.- int[]- toArray()Returns a new array of the values in the array.Converts the array to an ArrayList of Integer's.- Integer[]Returns an array of Integer values of the array.- voidTrims this list so that it wastes no space and its capacity is equal to its size.
- Field Details- EMPTYpublic static final int[] EMPTYEmpty array.
 
- Constructor Details- IntArrayListpublic IntArrayList()Creates an array with an initial capacity of 16.
- IntArrayListpublic IntArrayList- (int size) Creates an array with an initial capacity.- Parameters:
- size- The initial capacity of the list.
 
- IntArrayListpublic IntArrayList- (int[] values) Creates an array with a set of values.- Parameters:
- values- The values for the list.
 
- IntArrayListCreates an array from an ArrayList of Integer's.- Parameters:
- list- The ArrayList.
- Throws:
- NullPointerException- If any of the Integer items in the list is null.
 
 
- Method Details- sizepublic int size()Returns the size of the array.- Returns:
- The number of elements in the array.
 
- isEmptypublic boolean isEmpty()Checks if the array is empty.- Returns:
- Whether this list is empty of elements.
 
- clearpublic void clear()Clears the array, i.e. setting its size to 0.
- getpublic int get- (int index) Gets the value in the array at the given index.- Parameters:
- index- The index of the value to get.
- Returns:
- The value at the given index.
 
- addpublic void add- (int value) Adds a value to the end of the array.- Parameters:
- value- The value to add to the array.
 
- addpublic void add- (int index, int value) Adds a value to this list at the given index- Parameters:
- index- The index to add the value at
- value- The value to add to the list
 
- addAllpublic void addAll- (int[] values) Adds an array of values to the end of this array.- Parameters:
- values- The values to add.
 
- addAllAdds an array of values to the end of this array.- Parameters:
- list- The list of values to add.
 
- setpublic int set- (int index, int value) Replaces a value in this list with another value.- Parameters:
- index- The index of the value to replace.
- value- The value to replace the old value with.
- Returns:
- The old value at the given index.
 
- removepublic int remove- (int index) Removes a value from this list- Parameters:
- index- The index of the value to remove
- Returns:
- The value that was removed
 
- removeValuepublic boolean removeValue- (int value) Removes the first occurrence of a value from this array.- Parameters:
- value- The value to remove.
- Returns:
- Whether the value was found and removed.
 
- removeAllpublic int removeAll- (int value) Removes all instances of the given value from this array.- Parameters:
- value- The value to remove.
- Returns:
- The count of values removed.
 
- containspublic boolean contains- (int value) Determines if this array contains a given value.- Parameters:
- value- The value to find.
- Returns:
- Whether this array contains the given value.
 
- instanceCountpublic int instanceCount- (int value) Counts the number of times a value is represented in this array.- Parameters:
- value- The value to count.
- Returns:
- The count of values in this array.
 
- indexOfpublic int indexOf- (int value) Finds the index of a value in this array.- Parameters:
- value- The value to find.
- Returns:
- The first index whose value is the given value.
 
- lastIndexOfpublic int lastIndexOf- (int value) Finds the index of a value in this array from the array's tail.- Parameters:
- value- The value to find.
- Returns:
- The last index whose value is the given value.
 
- toArraypublic int[] toArray()Returns a new array of the values in the array.- Returns:
- An array of values currently in this array.
 
- toArrayListConverts the array to an ArrayList of Integer's.- Returns:
- A new instance of an ArrayList of Integer's.
 
- toObjectArrayReturns an array of Integer values of the array.- Returns:
- The array of values currently in this array as Integer's.
 
- trimToSizepublic void trimToSize()Trims this list so that it wastes no space and its capacity is equal to its size.
- ensureCapacitypublic void ensureCapacity- (int minCapacity) Ensures that this list's capacity is at list the given value.- Parameters:
- minCapacity- The minimum capacity for the list.