- Type Parameters:
E
- the type of the elements in the list
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,List<E>
LinkedList
, but exclusively
focused on list manipulation while disregarding the queue-like aspects of linked
lists. Functionally, this class is exactly equivalent to WiredList
. The
difference lies in how the two classes deal with removed elements and list
segments. WiredList
(like LinkedList
) meticulously nullifies
everything that can be nullified about them. CrisprList
just leaves them
floating in deep space (the heap). In principle the first strategy should make it
easier for the garbage collector to detect unreachable chunks of heap memory. The
extra administration can itself become non-negligible, however, when removing
large list segments, or when repetitively removing medium-sized list segments.- Author:
- Ayco Holleman
- See Also:
-
Constructor Summary
ConstructorDescriptionCreates a new, emptyCrisprList
.CrisprList
(Collection<? extends E> c) Creates a newCrisprList
containing the elements in the specifiedCollection
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Inserts the specified element at the specified position in this list.boolean
Appends the specified element to the end of this list.boolean
addAll
(int index, Collection<? extends E> c) Inserts all elements in the specified collection into this list at the specified position (optional operation).boolean
addAll
(Collection<? extends E> c) Appends all elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.Appends the specified value to the end of the list.appendAll
(Collection<? extends E> values) Appends the specified collection to thisCrisprList
.attach
(CrisprList<? extends E> other) Appends the specified list to this list.void
clear()
Removes all elements from this list.boolean
Returnstrue
if this list contains the specified element.boolean
containsAll
(Collection<?> c) Returnstrue
if this list contains all of the elements of the specified collection.copy()
Returns a copy of thisCrisprList
.copy
(int fromIndex, int toIndex) Returns a copy of the specified segment.cut
(int fromIndex, int toIndex) Removes and returns a segment from the list.defragment
(boolean keepRemainder, List<Predicate<? super E>> criteria) Reorders the elements according to the specified criteria.defragment
(List<Predicate<? super E>> criteria) Reorders the elements according to the specified criteria.embed
(int index, CrisprList<? extends E> other) Embeds the specified list in this list.embed
(int myIndex, CrisprList<? extends E> other, int itsFromIndex, int itsToIndex) Removes a segment from the specified list and embeds it in this list.boolean
Compares the specified object with this list for equality.exchange
(int myFromIndex, int myToIndex, CrisprList<E> other, int itsFromIndex, int itsToIndex) Exchanges list segments between this list and the specified list.first()
Returns the first element of the list.get
(int index) Returns the element at the specified position in this list.Groups the elements in those that do, and elements that do not satisfy the specified criterion.Groups the elements according to the provided criteria.int
hashCode()
Returns the hash code value for this list.int
Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.Inserts a value into the list.insertAll
(int index, Collection<? extends E> values) Inserts the specified collection at the specified index, right-shifting the elements at and following the index.boolean
isEmpty()
Returnstrue
if this list contains no elements.iterator()
Returns anIterator
that traverses the list from the first element to the last.static <E> CrisprList<E>
join
(List<CrisprList<E>> lists) Concatenates the providedCrisprList
instances.last()
Returns the last element of the list.int
Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.Removes and returns a segment from the start of the list.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.move
(int fromIndex, int toIndex, int newFromIndex) Moves a list segment forwards or backwards through the list.static <E> CrisprList<E>
of()
Returns a new, emptyCrisprList
.static <E> CrisprList<E>
of
(E e) Returns a newCrisprList
containing the specified element.static <E> CrisprList<E>
of
(E e0, E e1) Returns a newCrisprList
containing the specified elements.static <E> CrisprList<E>
of
(E e0, E e1, E e2, E... moreElems) Returns a newCrisprList
containing the specified elements.static <E> CrisprList<E>
ofElements
(E[] elements) Returns a newCrisprList
containing the specified elements.partition
(int size) Splits thisCrisprList
into multipleCrisprList
instances of the specified size.CrisprList<? super E>
paste
(CrisprList<? super E> into, int index) Inserts this list into the specified list at the specified position.Inserts the specified value at the start of the list, right-shifting the original elements.prependAll
(Collection<? extends E> values) Inserts the specified collection at the start of the list, right-shifting the original elements.Removes and returns a segment from the end of the list.Object[]
regionToArray
(int fromIndex, int toIndex) Returns an array containing the elements within the specified region of this list.void
regionToArray
(int fromIndex, int toIndex, Object[] target, int offset) Copies the specified region within this list to the specified position within the specified array.remove
(int index) Removes the element at the specified position in this list.boolean
Removes the first occurrence of the specified element from this list, if it is present.boolean
removeAll
(Collection<?> c) Removes the first element from the list, left-shifting the remaining elements.boolean
Removes all elements of this collection that satisfy the given predicate.Removes the last element from the list.replace
(int fromIndex, int toIndex, CrisprList<? extends E> other) Replaces the segment betweenfromIndex
andtoIndex
with the elements in the specified list.replaceAll
(int fromIndex, int toIndex, Collection<? extends E> values) Replaces the segment betweenfromIndex
andtoIndex
with the elements in the specified collection.void
replaceAll
(UnaryOperator<E> operator) Replaces each element of this list with the result of applying the operator to that element.boolean
retainAll
(Collection<?> c) reverse()
Reverses the order of the elements in thisCrisprList
.Returns anIterator
that traverses the list from the last element to the first.Replaces the element at the specified position in this list with the specified element.Overwrites the elements at, and following the specified index with the provided values.Sets the element at the specified index to the specified value if the original value passes the specified test.shrink
(int fromIndex, int toIndex) Shrinks the list to between the specified boundaries.int
size()
Returns the number of elements in this list.split
(int numPartitions) Splits thisCrisprList
into the specified number of equally-sizedCrisprList
instances.subList
(int fromIndex, int toIndex) Throws anUnsupportedOperationException
.swap
(int from1, int to1, int from2, int to2) Swaps the two list segments defined by the specified boundary indexes.Object[]
toArray()
Returns an array containing all elements in this list in proper sequence (from first to last element).<T> T[]
toArray
(T[] a) Returns an array containing all elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.toString()
Returns aString
representation of this list.Returns aWiredIterator
that traverses the list from the first element to the last.wiredIterator
(boolean reverse) Returns aWiredIterator
that traverses the list from the first element to the last, or the other way round, depending on the value of the argumentMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
Methods inherited from interface java.util.List
sort, spliterator
-
Constructor Details
-
CrisprList
public CrisprList()Creates a new, emptyCrisprList
. -
CrisprList
Creates a newCrisprList
containing the elements in the specifiedCollection
.- Parameters:
c
- the collection whose elements to copy to thisCrisprList
-
-
Method Details
-
of
Returns a new, emptyCrisprList
. Note that, although theof(..)
methods look like theList.of(...)
methods, they return ordinary, mutable,null
-acceptingCrisprList
instances.- Type Parameters:
E
- the type of the elements in the list- Returns:
- a new, empty
CrisprList
-
of
Returns a newCrisprList
containing the specified element.- Type Parameters:
E
- the type of the elements in the list- Parameters:
e
- the element- Returns:
- a new
CrisprList
containing the specified elements
-
of
Returns a newCrisprList
containing the specified elements.- Type Parameters:
E
- the type of the elements in the list- Parameters:
e0
- the first element in the liste1
- the second element in the list- Returns:
- a new
CrisprList
containing the specified elements
-
of
Returns a newCrisprList
containing the specified elements.- Type Parameters:
E
- the type of the elements in the list- Parameters:
e0
- the first element in the liste1
- the second element in the liste2
- the third element in the listmoreElems
- more elements to include in the list- Returns:
- a new
CrisprList
containing the specified elements
-
ofElements
Returns a newCrisprList
containing the specified elements.- Type Parameters:
E
- the type of the elements in the list- Parameters:
elements
- the elements to add to the list- Returns:
- a new
CrisprList
containing the specified elements
-
join
Concatenates the providedCrisprList
instances. This is a destructive operation for theCrisprList
instances in the providedList
. They will be empty when the method returns.- Type Parameters:
E
- the type of the elements in the list- Parameters:
lists
- theCrisprList
instances to concatenate- Returns:
- a new
CrisprList
containing the elements in the individualCrisprList
instances - See Also:
-
set
Overwrites the elements at, and following the specified index with the provided values. For linked lists this is more efficient than setting each of the elements individually, especially if the elements are somewhere in the middle of the lists. The number of values must not exceedlist.size() - index
.- Parameters:
index
- the index of the first element the sete0
- the first value to writee1
- the second value to writemoreElems
- more values to write- Returns:
- this instance
-
setIf
Sets the element at the specified index to the specified value if the original value passes the specified test. This method mitigates the relatively large cost of index-based retrieval with linked lists, which would double if you had to execute a get-compare-set sequence.- Parameters:
index
- the index of the element to setcondition
- The test that the original value has to pass in order to be replaced with the new value. The original value is passed to the predicate'stest
method.value
- The value to set- Returns:
- The original value
-
remove
Removes the element at the specified position in this list.- Parameters:
index
- the index of the element to be removed- Returns:
- the element previously at the specified position
- Throws:
IndexOutOfBoundsException
- if the index is out of range (index < 0 || index >= size()
)
-
remove
Removes the first occurrence of the specified element from this list, if it is present.- Parameters:
o
- element to be removed from this list, if present- Returns:
true
if this list contained the specified element
-
removeIf
Removes all elements of this collection that satisfy the given predicate.- Parameters:
filter
- a predicate which returnstrue
for elements to be removed- Returns:
true
if any elements were removed
-
first
Returns the first element of the list. ANoSuchElementException
is thrown if the list is empty.- Returns:
- the first element of the list
-
last
Returns the last element of the list. ANoSuchElementException
is thrown if the list is empty.- Returns:
- the last element of the list
-
prepend
Inserts the specified value at the start of the list, right-shifting the original elements.- Parameters:
value
- The value to insert- Returns:
- this instance
-
prependAll
Inserts the specified collection at the start of the list, right-shifting the original elements.- Parameters:
values
- The values to prepend to the list- Returns:
- this instance
-
append
Appends the specified value to the end of the list. Equivalent toadd(value)
.- Parameters:
value
- The value to append to the list- Returns:
- this instance
-
appendAll
Appends the specified collection to thisCrisprList
.- Parameters:
values
- The values to append to the list- Returns:
- this instance
- See Also:
-
insert
Inserts a value into the list. All elements at and following the specified index will be right-shifted. The index value must be>= 0
and<= list.size()
. Specifying 0 (zero) is equivalent toprepend(value)
. Specifyinglist.size()
is equivalent toappend(value
andadd(value)
.- Parameters:
index
- the index at which to insert the valuevalue
- the value- Returns:
- this instance
-
insertAll
Inserts the specified collection at the specified index, right-shifting the elements at and following the index.- Parameters:
index
- the index at which to insert the collectionvalues
- The collection to insert into the list- Returns:
- this instance
- See Also:
-
removeFirst
Removes the first element from the list, left-shifting the remaining elements. ANoSuchElementException
is thrown if the list is empty.- Returns:
- this instance
-
removeLast
Removes the last element from the list. ANoSuchElementException
is thrown if the list is empty.- Returns:
- this instance
-
replaceAll
Replaces each element of this list with the result of applying the operator to that element. Errors or runtime exceptions thrown by the operator are relayed to the caller.- Parameters:
operator
- the operator to apply to each element- Throws:
UnsupportedOperationException
- if this list is unmodifiable. Implementations may throw this exception if an element cannot be replaced or if, in general, modification is not supported
-
replaceAll
Replaces the segment betweenfromIndex
andtoIndex
with the elements in the specified collection.- Parameters:
fromIndex
- the start index (inclusive) of the segment to replacetoIndex
- the end index (exclusive) ofvalues
- The values to replace the segment with- Returns:
- this instance
- See Also:
-
replace
Replaces the segment betweenfromIndex
andtoIndex
with the elements in the specified list. This method is functionally equivalent toreplace
, but more efficient. However, it will leave the specified list empty. If you don't want this to happen, usereplaceAll
.- Parameters:
fromIndex
- the start index (inclusive) of the segment to replacetoIndex
- the end index (exclusive) ofother
- the values to replace the segment with- Returns:
- this instance
-
copy
Returns a copy of thisCrisprList
. Changes made to the copy will not propagate to this instance, and vice versa.- Returns:
- a deep copy of this
CrisprList
-
copy
Returns a copy of the specified segment. Changes made to the copy will not propagate to this instance, and vice versa.- Parameters:
fromIndex
- the start index (inclusive) of the segmenttoIndex
- the end index (exclusive) of the segment- Returns:
- a deep copy of the specified segment
-
shrink
Shrinks the list to between the specified boundaries. IftoIndex
is equal tofromIndex
, the list will, in effect, becleared
.- Parameters:
fromIndex
- the index (inclusive) of the new start of the listtoIndex
- the index (exclusive) of the new end of the list- Returns:
- this instance
-
cut
Removes and returns a segment from the list.- Parameters:
fromIndex
- the start index (inclusive) of the segment to deletetoIndex
- the end index (exclusive) of the segment to delete- Returns:
- the deleted segment
-
paste
Inserts this list into the specified list at the specified position. Equivalent tointo.embed(index, this)
. This list will be empty afterwards. Note that this method does not return list list but the paste-into list.- Parameters:
into
- the list into which to insert this listindex
- the index at which to insert this list- Returns:
- the specified list
-
embed
Embeds the specified list in this list. This method is functionally equivalent toinsertAll
andaddAll
, but more efficient. However, it is a destructive operation for the provided list. It will be empty afterwards. If you don't want this to happen, useinsertAll
oraddAll
.- Parameters:
index
- the index at which to embed the listother
- the list to embed- Returns:
- this instance
-
exchange
public CrisprList<E> exchange(int myFromIndex, int myToIndex, CrisprList<E> other, int itsFromIndex, int itsToIndex) Exchanges list segments between this list and the specified list.- Parameters:
myFromIndex
- the start index (inclusive) of the segment within this listmyToIndex
- the end index (exclusive) of the segment within this listother
- the list to exchange segments withitsFromIndex
- the start index (inclusive) of the segment within the other listitsToIndex
- the end index (exclusive) of the segment within the other list- Returns:
- this instance
-
embed
public CrisprList<E> embed(int myIndex, CrisprList<? extends E> other, int itsFromIndex, int itsToIndex) Removes a segment from the specified list and embeds it in this list.- Parameters:
myIndex
- the index at which to insert segmentother
- the list to remove the segment fromitsFromIndex
- the start index of the segment (inclusive)itsToIndex
- the end index of the segment (exclusive)- Returns:
- this instance
-
swap
Swaps the two list segments defined by the specified boundary indexes. In other words, once this method returns, the first list segment will start where the second list segment originally started, and vice versa. The list segments must not overlap and they must both contain at least one element. They need not have the same number of elements, though.- Parameters:
from1
- the from-index (inclusive) of the first segmentto1
- the to-index (exclusive) of the first segmentfrom2
- the from-index (inclusive) of the second segmentto2
- the to-index (exclusive) of the second segment- Returns:
- this
WiredList
-
attach
Appends the specified list to this list. This method is functionally equivalentappendAll
andaddAll
, but more efficient. However, it will leave the specified list empty. If you don't want this to happen, useappendAll
oraddAll
.- Parameters:
other
- the list to embed- Returns:
- this instance
- See Also:
-
defragment
Reorders the elements according to the specified criteria. The elements satisfying the first criterion (if any) will come first in the list, the elements satisfying the second criterion (if any) will come second, etc. The elements that did not satisfy any criterion will come last in the list.- Parameters:
criteria
- the criteria used to group the elements- Returns:
- this instance
-
defragment
Reorders the elements according to the specified criteria. The elements satisfying the first criterion (if any) will come first in the list, the elements satisfying the second criterion (if any) will come second, etc.- Parameters:
keepRemainder
- whether to keep the elements that did not satisfy any criterion, and move them to the end of the listcriteria
- the criteria used to group the elements- Returns:
- this instance
-
group
Groups the elements in those that do, and elements that do not satisfy the specified criterion.- Type Parameters:
L0
- the type of the lists within the returned listL1
- the type of returned list- Parameters:
criterion
- the test to submit the list elements to- Returns:
- a list containing two lists representing the two groups
- See Also:
-
group
Groups the elements according to the provided criteria. The return value is a list-of-lists where each inner
List
constitutes a group. ThisCrisprList
is left with all elements that did not satisfy any criterion, and it will be the last element in the returned list-of-lists. In other words, the size of the returned list-of-lists is the number of criteria plus one. You can use thejoin
method to create a single "defragmented" list again.Elements will never be placed in more than one group. As soon as an element is found to satisfy a criterion it is placed in the corresponding group and the remaining criteria are skipped.
The runtime type of the returned list-of-lists
CrisprList<CrisprList<E>>
. If you don't care about the exact type of the returnedList
, you can simply write:CrisprList<String> cl = ...; List<List<String>> groups = cl.group(...);
Otherwise use any combination of
List
andCrisprList
that suits your needs.- Type Parameters:
L0
- the type of the lists within the returned listL1
- the type of returned list- Parameters:
criteria
- the criteria used to group the elements- Returns:
- a list of element groups
-
partition
Splits thisCrisprList
into multipleCrisprList
instances of the specified size. The partitions are chopped off from theCrisprList
and then placed in a separateCrisprList
. The last element in the returned list-of-lists is thisCrisprList
, and it will now contain at mostsize
elements.The runtime type of the return value is
CrisprList<CrisprList<E>>
. If you don't care about the exact type of the returnedList
, you can simply write:CrisprList<String> cl = ...; List<List<String>> partitions = cl.partition(3);
Otherwise use any combination of
List
andCrisprList
that suits your needs.- Type Parameters:
L0
- the type of the lists within the returned listL1
- the type of returned list- Parameters:
size
- The desired size of the partitions- Returns:
- a list of
CrisprList
instances of the specified size
-
split
Splits thisCrisprList
into the specified number of equally-sizedCrisprList
instances. The last element in the returned list-of-lists is thisCrisprList
, and it will contain the remainder of the elements after dividing the list size bynumPartitions
. The runtime type of the return value isCrisprList<CrisprList<E>>
. If you don't care about the exact type of the returnedList
, you can simply write:CrisprList<String> cl = ...; List<List<String>> partitions = cl.split(3);
Otherwise use any combination of
List
andCrisprList
that suits your needs.- Type Parameters:
L0
- the type of the lists within the returned listL1
- the type of returned list- Parameters:
numPartitions
- The number ofCrisprList
instances to split thisCrisprList
into- Returns:
- a list containing the specified number of
CrisprList
instances
-
lchop
Removes and returns a segment from the start of the list. The segment will include all elements up to (but not including) the first element that does not satisfy the specified condition. In other words, all elements in the returned list will satisfy the condition. If the condition is never satisfied, this list remains unchanged and an empty list is returned. If all elements satisfy the condition, the list remains unchanged and is itself returned.- Parameters:
criterion
- the criterion that the elements in the returned segment will satisfy- Returns:
- a
CrisprList
containing all elements preceding the first element that does not satisfy the condition; possibly this instance
-
rchop
Removes and returns a segment from the end of the list. The segment will include all elements following the last element that does not satisfy the specified condition. In other words, all elements in the returned list will satisfy the condition. If the condition is never satisfied, the list remains unchanged and an empty list is returned. If all elements satisfy the condition, the list remains unchanged and is itself returned.- Parameters:
criterion
- the criterion that the elements in the returned segment will satisfy- Returns:
- a
CrisprList
containing all elements following the last element that does not satisfy the condition; possibly this instance
-
reverse
Reverses the order of the elements in thisCrisprList
.- Returns:
- this instance
-
move
Moves a list segment forwards or backwards through the list.- Parameters:
fromIndex
- the start index of the segment (inclusive)toIndex
- the end index of the segment (exclusive)newFromIndex
- the index to which to move the segment. To move the segment to the very start of the list, specify 0 (zero). To move the segment to the very end of the list specify thesize
of the list- Returns:
- this instance
-
clear
public void clear()Removes all elements from this list. The list will be empty after this call returns. -
reverseIterator
Returns anIterator
that traverses the list from the last element to the first. See alsoList.iterator()
.- Returns:
- an
Iterator
that traverses the list from the last element to the first
-
wiredIterator
Returns aWiredIterator
that traverses the list from the first element to the last.- Returns:
- a
WiredIterator
that traverses the list from the first element to the last
-
wiredIterator
Returns aWiredIterator
that traverses the list from the first element to the last, or the other way round, depending on the value of the argument- Parameters:
reverse
- Whether to iterate from the first to the last (false
), or from the last to the first (true
)- Returns:
- a
WiredIterator
that traverses the list from the first element to the last, or the other way round
-
regionToArray
Returns an array containing the elements within the specified region of this list.- Parameters:
fromIndex
- the start index (inclusive) of the regiontoIndex
- the end index (exclusive) of the region- Returns:
- an array containing the elements within the specified region of this list
-
regionToArray
Copies the specified region within this list to the specified position within the specified array. The array must be large enough to copy the entire region to the specified position.- Parameters:
fromIndex
- the start index (inclusive) of the regiontoIndex
- the end index (exclusive) of the regiontarget
- the array to which to copy the elementsoffset
- the offset within the array
-
subList
Throws anUnsupportedOperationException
. The specification for this method requires that non-structural changes in the returned list are reflected in the original list (and vice versa). However, except for theList.set(int, Object)
method, all changes to aCrisprList
are structural changes.CrisprList
does provide a method that returns a sublist (copy
). It just has no relation to the original list any longer. -
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 indexi
such thatObjects.equals(o, 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 indexi
such thatObjects.equals(o, get(i))
, or -1 if there is no such index.- Specified by:
lastIndexOf
in interfaceList<E>
- Parameters:
o
- element to search for- Returns:
- the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element
-
get
Returns the element at the specified position in this list.- Specified by:
get
in interfaceList<E>
- Parameters:
index
- index of the element to return- Returns:
- the element at the specified position in this list
- Throws:
IndexOutOfBoundsException
- if the index is out of range (index < 0 || index >= size()
)
-
set
Replaces the element at the specified position in this list with the specified element. -
add
Appends the specified element to the end of this list.- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceList<E>
- Parameters:
e
- element to be appended to this list- Returns:
true
(as specified byCollection.add(E)
)
-
add
Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices). -
addAll
Appends all elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.- Specified by:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in interfaceList<E>
- Parameters:
c
- collection containing elements to be added to this list- Returns:
true
if this list changed as a result of the call- See Also:
-
addAll
Inserts all elements in the specified collection into this list at the specified position (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). -
size
public int size()Returns the number of elements in this list. If this list contains more thanInteger.MAX_VALUE
elements, returnsInteger.MAX_VALUE
.- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceList<E>
- Returns:
- the number of elements in this list
-
isEmpty
public boolean isEmpty()Returnstrue
if this list contains no elements.- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceList<E>
- Returns:
true
if this list contains no elements
-
contains
Returnstrue
if this list contains the specified element. More formally, returnstrue
if and only if this list contains at least one elemente
such thatObjects.equals(o, e)
.- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceList<E>
- Parameters:
o
- element whose presence in this list is to be tested- Returns:
true
if this list contains the specified element
-
containsAll
Returnstrue
if this list contains all of the elements of the specified collection.- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceList<E>
- Parameters:
c
- collection to be checked for containment in this list- Returns:
true
if this list contains all of the elements of the specified collection- See Also:
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceList<E>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E>
- Specified by:
retainAll
in interfaceList<E>
-
iterator
Returns anIterator
that traverses the list from the first element to the last. -
listIterator
Returns a list iterator over the elements in this list (in proper sequence).- Specified by:
listIterator
in interfaceList<E>
- Returns:
- a list iterator over the elements in this list (in proper sequence)
-
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 toprevious
would return the element with the specified index minus one.- Specified by:
listIterator
in interfaceList<E>
- Parameters:
index
- index of the first element to be returned from the list iterator (by a call tonext
)- Returns:
- a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list
- Throws:
IndexOutOfBoundsException
- if the index is out of range (index < 0 || index > size()
)
-
equals
Compares the specified object with this list for equality. Returnstrue
if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elementse1
ande2
are equal ifObjects.equals(e1, e2)
.) In other words, two lists are defined to be equal if they contain the same elements in the same order. This definition ensures that the equals method works properly across different implementations of theList
interface. -
hashCode
public int hashCode()Returns the hash code value for this list. -
toString
Returns aString
representation of this list. -
toArray
Returns an array containing all elements in this list in proper sequence (from first to last element).- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceList<E>
- Returns:
- an array containing all elements in this list in proper sequence
- See Also:
-
toArray
public <T> T[] toArray(T[] a) Returns an array containing all elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceList<E>
- Parameters:
a
- the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.- Returns:
- an array containing the elements of this list
- Throws:
ArrayStoreException
- if the runtime type of the specified array is not a supertype of the runtime type of every element in this listNullPointerException
- if the specified array is null
-