Class ArrayListOfLong
- All Implemented Interfaces:
Cloneable,Iterable<Long>,Collection<Long>,List<Long>,RandomAccess,SequencedCollection<Long>,ListOfLong
- Author:
- jjdelcerro
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty list with an initial capacity of ten.ArrayListOfLong(int initialCapacity) Constructs an empty list with the specified initial capacity.ArrayListOfLong(Collection<? extends Long> c) Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int index, long element) voidbooleanadd(long e) booleanbooleanaddAll(int index, Collection<? extends Long> c) Inserts all of the elements in the specified collection into this list, starting at the specified position.booleanaddAll(Collection<? extends Long> c) Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's Iterator.voidclear()Removes all of the elements from this list.clone()Returns a shallow copy of this ArrayList instance.booleanReturns true if this list contains the specified element.voidensureCapacity(int minCapacity) Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.voidget(int index) longgetLong(int index) intReturns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.booleanisEmpty()Returns true if this list contains no elements.iterator()Returns an iterator over the elements in this list in proper sequence.intReturns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.Returns a list iterator over the elements in this list (in proper sequence).listIterator(int index) Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.remove(int index) booleanbooleanremoveAll(Collection<?> c) Removes from this list all of its elements that are contained in the specified collection.booleanbooleanremoveLong(long o) protected voidremoveRange(int fromIndex, int toIndex) Removes from this list all of the elements whose index is betweenfromIndex, inclusive, andtoIndex, exclusive.voidreplaceAll(UnaryOperator<Long> operator) booleanretainAll(Collection<?> c) Retains only the elements in this list that are contained in the specified collection.Replaces the element at the specified position in this list with the specified element.intsize()Returns the number of elements in this list.voidsort(Comparator<? super Long> c) Creates a late-binding and fail-fastSpliteratorover the elements in this list.subList(int fromIndex, int toIndex) Returns a view of the portion of this list between the specifiedfromIndex, inclusive, andtoIndex, exclusive.Long[]toArray()Long[]voidTrims the capacity of this ArrayList instance to be the list's current size.Methods inherited from class java.util.AbstractList
equals, hashCodeMethods inherited from class java.util.AbstractCollection
containsAll, toArray, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods inherited from interface java.util.List
addFirst, addLast, containsAll, equals, getFirst, getLast, hashCode, removeFirst, removeLast, reversed, toArray
-
Constructor Details
-
ArrayListOfLong
public ArrayListOfLong(int initialCapacity) Constructs an empty list with the specified initial capacity.- Parameters:
initialCapacity- the initial capacity of the list- Throws:
IllegalArgumentException- if the specified initial capacity is negative
-
ArrayListOfLong
public ArrayListOfLong()Constructs an empty list with an initial capacity of ten. -
ArrayListOfLong
Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.- Parameters:
c- the collection whose elements are to be placed into this list- Throws:
NullPointerException- if the specified collection is null
-
-
Method Details
-
trimToSize
public void trimToSize()Trims the capacity of this ArrayList instance to be the list's current size. An application can use this operation to minimize the storage of an ArrayList instance. -
ensureCapacity
public void ensureCapacity(int minCapacity) Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.- Parameters:
minCapacity- the desired minimum capacity
-
size
public int size()Returns the number of elements in this list.- Specified by:
sizein interfaceCollection<Long>- Specified by:
sizein interfaceList<Long>- Specified by:
sizein classAbstractCollection<Long>- Returns:
- the number of elements in this list
-
isEmpty
public boolean isEmpty()Returns true if this list contains no elements.- Specified by:
isEmptyin interfaceCollection<Long>- Specified by:
isEmptyin interfaceList<Long>- Overrides:
isEmptyin classAbstractCollection<Long>- Returns:
- true if this list contains no elements
-
contains
Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).- Specified by:
containsin interfaceCollection<Long>- Specified by:
containsin interfaceList<Long>- Overrides:
containsin classAbstractCollection<Long>- Parameters:
o- element whose presence in this list is to be tested- Returns:
- true if this list contains the specified element
-
indexOf
Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index. -
lastIndexOf
Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the highest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.- Specified by:
lastIndexOfin interfaceList<Long>- Overrides:
lastIndexOfin classAbstractList<Long>
-
clone
Returns a shallow copy of this ArrayList instance. (The elements themselves are not copied.) -
toArray
- Specified by:
toArrayin interfaceCollection<Long>- Specified by:
toArrayin interfaceList<Long>- Overrides:
toArrayin classAbstractCollection<Long>
-
toArray
-
get
-
getLong
public long getLong(int index) - Specified by:
getLongin interfaceListOfLong
-
set
Replaces the element at the specified position in this list with the specified element. -
add
- Specified by:
addin interfaceCollection<Long>- Specified by:
addin interfaceList<Long>- Overrides:
addin classAbstractList<Long>
-
add
public boolean add(long e) - Specified by:
addin interfaceListOfLong
-
add
-
add
public void add(int index, long element) -
remove
-
remove
- Specified by:
removein interfaceCollection<Long>- Specified by:
removein interfaceList<Long>- Overrides:
removein classAbstractCollection<Long>
-
removeLong
public boolean removeLong(long o) - Specified by:
removeLongin interfaceListOfLong
-
clear
public void clear()Removes all of the elements from this list. The list will be empty after this call returns.- Specified by:
clearin interfaceCollection<Long>- Specified by:
clearin interfaceList<Long>- Overrides:
clearin classAbstractList<Long>
-
addAll
Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's Iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this list, and this list is nonempty.)- Specified by:
addAllin interfaceCollection<Long>- Specified by:
addAllin interfaceList<Long>- Overrides:
addAllin classAbstractCollection<Long>- Parameters:
c- collection containing elements to be added to this list- Returns:
- true if this list changed as a result of the call
- Throws:
NullPointerException- if the specified collection is null
-
addAll
Inserts all of the elements in the specified collection into this list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the list in the order that they are returned by the specified collection's iterator.- Specified by:
addAllin interfaceList<Long>- Overrides:
addAllin classAbstractList<Long>- Parameters:
index- index at which to insert the first element from the specified collectionc- collection containing elements to be added to this list- Returns:
- true if this list changed as a result of the call
-
removeRange
protected void removeRange(int fromIndex, int toIndex) Removes from this list all of the elements whose index is betweenfromIndex, inclusive, andtoIndex, exclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the list by(toIndex - fromIndex)elements. (IftoIndex==fromIndex, this operation has no effect.)- Overrides:
removeRangein classAbstractList<Long>- Throws:
IndexOutOfBoundsException- iffromIndexortoIndexis out of range (fromIndex < 0 || fromIndex >= size() || toIndex > size() || toIndex < fromIndex)
-
removeAll
Removes from this list all of its elements that are contained in the specified collection.- Specified by:
removeAllin interfaceCollection<Long>- Specified by:
removeAllin interfaceList<Long>- Overrides:
removeAllin classAbstractCollection<Long>- Parameters:
c- collection containing elements to be removed from this list- Returns:
trueif this list changed as a result of the call- Throws:
ClassCastException- if the class of an element of this list is incompatible with the specified collection (optional)NullPointerException- if this list contains a null element and the specified collection does not permit null elements (optional), or if the specified collection is null- See Also:
-
retainAll
Retains only the elements in this list that are contained in the specified collection. In other words, removes from this list all of its elements that are not contained in the specified collection.- Specified by:
retainAllin interfaceCollection<Long>- Specified by:
retainAllin interfaceList<Long>- Overrides:
retainAllin classAbstractCollection<Long>- Parameters:
c- collection containing elements to be retained in this list- Returns:
trueif this list changed as a result of the call- Throws:
ClassCastException- if the class of an element of this list is incompatible with the specified collection (optional)NullPointerException- if this list contains a null element and the specified collection does not permit null elements (optional), or if the specified collection is null- See Also:
-
listIterator
Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. The specified index indicates the first element that would be returned by an initial call tonext. An initial call topreviouswould return the element with the specified index minus one.The returned list iterator is fail-fast.
- Specified by:
listIteratorin interfaceList<Long>- Overrides:
listIteratorin classAbstractList<Long>
-
listIterator
Returns a list iterator over the elements in this list (in proper sequence).The returned list iterator is fail-fast.
- Specified by:
listIteratorin interfaceList<Long>- Overrides:
listIteratorin classAbstractList<Long>- See Also:
-
iterator
Returns an iterator over the elements in this list in proper sequence.The returned iterator is fail-fast.
-
subList
Returns a view of the portion of this list between the specifiedfromIndex, inclusive, andtoIndex, exclusive. (IffromIndexandtoIndexare equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations.This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:
list.subList(from, to).clear();Similar idioms may be constructed forindexOf(Object)andlastIndexOf(Object), and all of the algorithms in theCollectionsclass can be applied to a subList.The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)
-
forEach
-
spliterator
Creates a late-binding and fail-fastSpliteratorover the elements in this list.The
SpliteratorreportsSpliterator.SIZED,Spliterator.SUBSIZED, andSpliterator.ORDERED. Overriding implementations should document the reporting of additional characteristic values.- Specified by:
spliteratorin interfaceCollection<Long>- Specified by:
spliteratorin interfaceIterable<Long>- Specified by:
spliteratorin interfaceList<Long>- Returns:
- a
Spliteratorover the elements in this list - Since:
- 1.8
-
removeIf
- Specified by:
removeIfin interfaceCollection<Long>
-
replaceAll
- Specified by:
replaceAllin interfaceList<Long>
-
sort
-