- All Implemented Interfaces:
Iterable<Integer>,Collection<Integer>,List<Integer>,SequencedCollection<Integer>,IntList,IntSequencedCollection
A
int-valued list backed by a primitive array.- Author:
- Werner Randelshofer
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new empty instance with 0 initial capacity.IntArrayList(int initialCapacity) Creates a new empty instance with the specified initial capacity.IntArrayList(Collection<Integer> collection) Creates a new instance from the specified collection -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidaddAllAsInt(IntArrayList that) Adds all items of the specified list to this list.<T extends Collection<Integer>>
TaddAllInto(T out) Adds all items of this collection to the specified collection.voidaddAsInt(int newItem) Adds a new item to the end of the list.voidaddAsInt(int index, int newItem) Inserts a new item at the specified index into this list.voidclear()Clears the list in O(1).booleanvoidcopyInto(int[] a, int offset) Copies the contents of this list into the provided array.booleanget(int index) int[]getArray()Gets the array that is used internally by this list.intgetAsInt(int index) Gets the item at the specified index.intintinthashCode()intindexOfAsInt(int item) intindexOfAsInt(int item, int start) Returns a stream for processing the items of this list.booleanisEmpty()Returns true if size==0.iterator()Returns an iterator for this list.intlastIndexOfAsInt(int item) intlastIndexOfAsInt(int item, int start) static IntArrayListof(int... items) Creates a new instance with the specified items.booleanintremoveAtAsInt(int index) Removes the item at the specified index from this list.booleanremoveIfAsInt(IntPredicate filter) Removes all the elements of this collection that satisfy the given predicate.intRemoves the last itemreversed()Replaces the item at the specified index.intsetAsInt(int index, int newItem) Replaces the item at the specified index.voidsetSize(int newSize) Sets the size of this list.intsize()Returns the size of the list.voidsort()Sorts the items in ascending order.voidsort(@Nullable Comparator<? super Integer> c) Sorts this list according to the order induced by the specifiedComparator.Returns a spliterator for this list.int[]Returns a new array containing all the elements in this collection.toString()voidTrims the capacity of the list its current size.Methods inherited from class java.util.AbstractList
add, addAll, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, subListMethods inherited from class java.util.AbstractCollection
addAll, containsAll, removeAll, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface org.jhotdraw8.collection.primitive.IntList
addFirst, addFirstAsInt, addLast, addLastAsInt, getFirst, getLast, indexOf, lastIndexOf, removeFirst, removeFirstAsInt, removeLastMethods inherited from interface org.jhotdraw8.collection.primitive.IntSequencedCollection
addLastAllAsInt, addLastAllAsIntMethods inherited from interface java.util.List
add, addAll, addAll, containsAll, listIterator, listIterator, remove, removeAll, replaceAll, retainAll, subList, toArray, toArray
-
Constructor Details
-
IntArrayList
public IntArrayList()Creates a new empty instance with 0 initial capacity. -
IntArrayList
public IntArrayList(int initialCapacity) Creates a new empty instance with the specified initial capacity.- Parameters:
initialCapacity- the initial capacity
-
IntArrayList
Creates a new instance from the specified collection- Parameters:
collection- a collection of integers
-
-
Method Details
-
of
Creates a new instance with the specified items.- Parameters:
items- the items (the newly created instance references the provided array)- Returns:
- the new instance
-
add
-
addAllAsInt
Adds all items of the specified list to this list.- Parameters:
that- another list
-
addAllInto
Adds all items of this collection to the specified collection.- Type Parameters:
T- the type of the collection- Parameters:
out- the output collection- Returns:
- out
-
addAsInt
public void addAsInt(int newItem) Adds a new item to the end of the list. -
addAsInt
public void addAsInt(int index, int newItem) Inserts a new item at the specified index into this list. -
clear
public void clear()Clears the list in O(1).- Specified by:
clearin interfaceCollection<Integer>- Specified by:
clearin interfaceList<Integer>- Overrides:
clearin classAbstractList<Integer>
-
contains
- Specified by:
containsin interfaceCollection<Integer>- Specified by:
containsin interfaceList<Integer>- Overrides:
containsin classAbstractCollection<Integer>
-
copyInto
public void copyInto(int[] a, int offset) Copies the contents of this list into the provided array.- Parameters:
a- an arrayoffset- the offset into the array
-
equals
- Specified by:
equalsin interfaceCollection<Integer>- Specified by:
equalsin interfaceList<Integer>- Overrides:
equalsin classAbstractList<Integer>
-
get
-
getArray
public int[] getArray()Gets the array that is used internally by this list.- Returns:
- the internal array
-
getAsInt
public int getAsInt(int index) Gets the item at the specified index. -
getFirstAsInt
public int getFirstAsInt()- Specified by:
getFirstAsIntin interfaceIntSequencedCollection
-
getLastAsInt
public int getLastAsInt()- Specified by:
getLastAsIntin interfaceIntSequencedCollection
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<Integer>- Specified by:
hashCodein interfaceList<Integer>- Overrides:
hashCodein classAbstractList<Integer>
-
indexOfAsInt
public int indexOfAsInt(int item) - Specified by:
indexOfAsIntin interfaceIntList- See Also:
-
indexOfAsInt
public int indexOfAsInt(int item, int start) -
intStream
Returns a stream for processing the items of this list.- Returns:
- a stream
-
isEmpty
public boolean isEmpty()Returns true if size==0. -
iterator
Returns an iterator for this list. -
lastIndexOfAsInt
public int lastIndexOfAsInt(int item) - Specified by:
lastIndexOfAsIntin interfaceIntList- See Also:
-
lastIndexOfAsInt
public int lastIndexOfAsInt(int item, int start) -
remove
- Specified by:
removein interfaceCollection<Integer>- Specified by:
removein interfaceList<Integer>- Overrides:
removein classAbstractCollection<Integer>
-
removeAtAsInt
public int removeAtAsInt(int index) Removes the item at the specified index from this list.- Specified by:
removeAtAsIntin interfaceIntList- Parameters:
index- an index- Returns:
- the removed item
-
removeIfAsInt
Removes all the elements of this collection that satisfy the given predicate.- Parameters:
filter- a predicate which returnstruefor elements to be removed- Returns:
trueif any elements were removed
-
removeLastAsInt
public int removeLastAsInt()Removes the last item- Specified by:
removeLastAsIntin interfaceIntSequencedCollection- Returns:
- the removed item
- Throws:
NoSuchElementException- if the list is empty
-
reversed
-
set
Replaces the item at the specified index. -
setAsInt
public int setAsInt(int index, int newItem) Replaces the item at the specified index.- Parameters:
index- an indexnewItem- the new item- Returns:
- the old item
-
setSize
public void setSize(int newSize) Sets the size of this list. If the new size is greater than the current size, new0items are added to the end of the list. If the new size is less than the current size, all items at indices greater or equalnewSizeare discarded.- Parameters:
newSize- the new size
-
size
public int size()Returns the size of the list.- Specified by:
sizein interfaceCollection<Integer>- Specified by:
sizein interfaceList<Integer>- Specified by:
sizein classAbstractCollection<Integer>- Returns:
- the size
-
sort
public void sort()Sorts the items in ascending order. -
sort
Sorts this list according to the order induced by the specifiedComparator. The sort is stable: it does not reorder equal elements.- Specified by:
sortin interfaceList<Integer>- Parameters:
c- theComparatorused to compare list elements. Anullvalue indicates that the elements' natural ordering should be used.
-
spliterator
Returns a spliterator for this list.- Specified by:
spliteratorin interfaceCollection<Integer>- Specified by:
spliteratorin interfaceIterable<Integer>- Specified by:
spliteratorin interfaceList<Integer>- Returns:
- a spliterator over the elements of this list
-
toIntArray
public int[] toIntArray()Returns a new array containing all the elements in this collection.- Returns:
- array
-
toString
- Overrides:
toStringin classAbstractCollection<Integer>
-
trimToSize
public void trimToSize()Trims the capacity of the list its current size.
-