- All Implemented Interfaces:
Iterable<Long>,Collection<Long>,List<Long>,SequencedCollection<Long>
A
long-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.LongArrayList(int initialCapacity) Creates a new empty instance with the specified initial capacity.LongArrayList(Collection<Long> collection) Creates a new instance from the specified collection -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidaddAllAsLong(LongArrayList that) Adds all items of the specified list to this list.<T extends Collection<Long>>
TaddAllInto(T out) Adds all items of this collection to the specified collection.voidaddAsLong(int index, long newItem) Inserts a new item at the specified index into this list.voidaddAsLong(long newItem) Adds a new item to the end of the list.voidclear()Clears the list in O(1).booleanvoidcopyInto(long[] a, int offset) Copies the contents of this list into the provided array.booleanget(int index) longgetAsLong(int index) Gets the item at the specified index.longlonginthashCode()intindexOfAsLong(long item) Returns the last index of the item, or -1 if this list does not contain the item.intindexOfAsLong(long item, int start) booleanisEmpty()Returns true if size==0.iterator()Returns an iterator for this list.intlastIndexOfAsLong(long item) intlastIndexOfAsLong(long item, int start) Returns a stream for processing the items of this list.static LongArrayListof(long... items) Creates a new instance with the specified items.booleanlongremoveAtAsLong(int index) Removes the item at the specified index from this list.booleanremoveIfAsLong(LongPredicate filter) Removes all the elements of this collection that satisfy the given predicate.longRemoves the last itemlongsetAsLong(int index, long 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 Long> c) Sorts this list according to the order induced by the specifiedComparator.Returns a spliterator for this list.long[]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, set, 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 java.util.List
addAll, addFirst, addLast, containsAll, getFirst, getLast, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, toArray, toArray
-
Constructor Details
-
LongArrayList
public LongArrayList()Creates a new empty instance with 0 initial capacity. -
LongArrayList
public LongArrayList(int initialCapacity) Creates a new empty instance with the specified initial capacity.- Parameters:
initialCapacity- the initial capacity
-
LongArrayList
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
-
addAsLong
public void addAsLong(long newItem) Adds a new item to the end of the list.- Parameters:
newItem- the new item
-
addAsLong
public void addAsLong(int index, long newItem) Inserts a new item at the specified index into this list.- Parameters:
index- the indexnewItem- the new item
-
addAllAsLong
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
-
clear
public void clear()Clears the list in O(1).- Specified by:
clearin interfaceCollection<Long>- Specified by:
clearin interfaceList<Long>- Overrides:
clearin classAbstractList<Long>
-
copyInto
public void copyInto(long[] 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<Long>- Specified by:
equalsin interfaceList<Long>- Overrides:
equalsin classAbstractList<Long>
-
getAsLong
public long getAsLong(int index) Gets the item at the specified index.- Parameters:
index- an index- Returns:
- the item at the index
-
get
-
getLastAsLong
public long getLastAsLong() -
getFirstAsLong
public long getFirstAsLong() -
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
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<Long>- Specified by:
hashCodein interfaceList<Long>- Overrides:
hashCodein classAbstractList<Long>
-
indexOfAsLong
public int indexOfAsLong(long item) Returns the last index of the item, or -1 if this list does not contain the item.- Parameters:
item- the item- Returns:
- the index of the item, or -1.
-
indexOfAsLong
public int indexOfAsLong(long item, int start) -
lastIndexOfAsLong
public int lastIndexOfAsLong(long item) -
lastIndexOfAsLong
public int lastIndexOfAsLong(long item, int start) -
isEmpty
public boolean isEmpty()Returns true if size==0.- Specified by:
isEmptyin interfaceCollection<Long>- Specified by:
isEmptyin interfaceList<Long>- Overrides:
isEmptyin classAbstractCollection<Long>- Returns:
- true if empty
-
contains
- Specified by:
containsin interfaceCollection<Long>- Specified by:
containsin interfaceList<Long>- Overrides:
containsin classAbstractCollection<Long>
-
removeAtAsLong
public long removeAtAsLong(int index) Removes the item at the specified index from this list.- Parameters:
index- an index- Returns:
- the removed item
-
removeLastAsLong
public long removeLastAsLong()Removes the last item- Returns:
- the removed item
- Throws:
NoSuchElementException- if the list is empty
-
setAsLong
public long setAsLong(int index, long newItem) Replaces the item at the specified index.- Parameters:
index- an indexnewItem- the new item- Returns:
- the old item
-
size
public int size()Returns the size of the list.- Specified by:
sizein interfaceCollection<Long>- Specified by:
sizein interfaceList<Long>- Specified by:
sizein classAbstractCollection<Long>- Returns:
- the size
-
trimToSize
public void trimToSize()Trims the capacity of the list its current size. -
iterator
Returns an iterator for this list. -
spliterator
Returns a spliterator for this list.- Returns:
- a spliterator over the elements of this list
-
longStream
Returns a stream for processing the items of this list.- Returns:
- a stream
-
toLongArray
public long[] toLongArray()Returns a new array containing all the elements in this collection.- Returns:
- array
-
add
- Specified by:
addin interfaceCollection<Long>- Specified by:
addin interfaceList<Long>- Overrides:
addin classAbstractList<Long>
-
remove
- Specified by:
removein interfaceCollection<Long>- Specified by:
removein interfaceList<Long>- Overrides:
removein classAbstractCollection<Long>
-
toString
- Overrides:
toStringin classAbstractCollection<Long>
-
sort
public void sort()Sorts the items in ascending order. -
removeIfAsLong
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
-
sort
Sorts this list according to the order induced by the specifiedComparator. The sort is stable: it does not reorder equal elements.- Parameters:
c- theComparatorused to compare list elements. Anullvalue indicates that the elements' natural ordering should be used.
-