- 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. As with any doubly-linked list, index-based retrieval is relatively costly
compared to ArrayList. It is very efficient, however, at inserting,
deleting and moving around chunks of list elements (i.e. structural changes). The
larger the chunks, the bigger the gain - again compared to ArrayList.
Iteration
You should always use an Iterator to iterate over the elements in the list
(which you implicitly would when executing a forEach loop). Using an
index/get loop is possible, but performs poorly. The Iterator and
ListIterator implementations prescribed by the List interface are
no-frills iterators that throw an UnsupportedOperationException from all
methods designated as optional by the specification. In addition, the
WiredList class also features a reverseIterator0() and a
wiredIterator() method. The latter returns an instance of the
WiredIterator interface. Unlike a ListIterator, this is a
one-way-only iterator, but it still provides the same functionality, and it
does implement the methods that are optional in the ListIterator
interface.
Fluent API
Many of the methods that go beyond those prescribed by the List interface
form part of a fluent API. This causes some overlap in functionality between
List methods and methods taking part in the fluent API. They are
implemented exactly alike, so there is intrinsic reason to prefer one over the
other.
Thread safety
List edits are always destructive, and nearly always don't just change the values
in the list, but the underlying data structure itself. The WiredList class
is not thread-safe. Multiple threads mutating the same list can leave it in a
seriously corrupted state, with "dangling wires" between the list elements (i.e.
null pointers). While the iterators make a light-touch effort to detect and trap
concurrent modifications on the list, WiredList itself doesn't. Therefore,
synchronize carefully when multiple threads access the same list.
- Author:
- Ayco Holleman
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new, emptyWiredList.WiredList(Collection<? extends E> c) Creates a newWiredListcontaining the elements in the specifiedCollection. -
Method Summary
Modifier and TypeMethodDescriptionvoidInserts the specified element at the specified position in this list.booleanAppends the specified element to the end of this list.booleanaddAll(int index, Collection<? extends E> c) Inserts all elements in the specified collection into this list at the specified position (optional operation).booleanaddAll(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 thisWiredList.Appends the specified list to this list.voidclear()Removes all elements from this list.booleanReturnstrueif this list contains the specified element.booleancontainsAll(Collection<?> c) Returnstrueif this list contains all of the elements of the specified collection.copy()Returns a copy of thisWiredList.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.Embeds the specified list in this list.Removes a segment from the specified list and embeds it in this list.booleanCompares the specified object with this list for equality.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.inthashCode()Returns the hash code value for this list.intReturns 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.booleanisEmpty()Returnstrueif this list contains no elements.iterator()Returns anIteratorthat traverses the list from the first element to the last.static <E> WiredList<E>Concatenates the providedWiredListinstances.last()Returns the last element of the list.intReturns 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> WiredList<E>of()Returns a new, emptyWiredList.static <E> WiredList<E>of(E e) Returns a newWiredListcontaining the specified element.static <E> WiredList<E>of(E e0, E e1) Returns a newWiredListcontaining the specified elements.static <E> WiredList<E>of(E e0, E e1, E e2, E... moreElems) Returns a newWiredListcontaining the specified elements.static <E> WiredList<E>ofElements(E[] elements) Returns a newWiredListcontaining the specified elements.partition(int size) Splits thisWiredListinto multipleWiredListinstances of the specified size.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.voidregionToArray(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.booleanRemoves the first occurrence of the specified element from this list, if it is present.booleanremoveAll(Collection<?> c) Removes the first element from the list, left-shifting the remaining elements.booleanRemoves all elements of this collection that satisfy the given predicate.Removes the last element from the list.Replaces the segment betweenfromIndexandtoIndexwith the elements in the specified list.replaceAll(int fromIndex, int toIndex, Collection<? extends E> values) Replaces the segment betweenfromIndexandtoIndexwith the elements in the specified collection.voidreplaceAll(UnaryOperator<E> operator) Replaces each element of this list with the result of applying the operator to that element.booleanretainAll(Collection<?> c) reverse()Reverses the order of the elements in thisWiredList.Returns anIteratorthat 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.intsize()Returns the number of elements in this list.split(int numPartitions) Splits thisWiredListinto the specified number of equally-sizedWiredListinstances.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 aStringrepresentation of this list.Returns aWiredIteratorthat traverses the list from the first element to the last.wiredIterator(boolean reverse) Returns aWiredIteratorthat 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, waitMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods inherited from interface java.util.List
sort, spliterator
-
Constructor Details
-
WiredList
public WiredList()Creates a new, emptyWiredList. -
WiredList
Creates a newWiredListcontaining the elements in the specifiedCollection.- Parameters:
c- the collection whose elements to copy to thisWiredList
-
-
Method Details
-
of
Returns a new, emptyWiredList. Note that, although theof(..)methods look like theList.of(...)methods, they return ordinary, mutable,null-acceptingWiredListinstances.- Type Parameters:
E- the type of the elements in the list- Returns:
- a new, empty
WiredList
-
of
Returns a newWiredListcontaining the specified element.- Type Parameters:
E- the type of the elements in the list- Parameters:
e- the element- Returns:
- a new
WiredListcontaining the specified elements
-
of
Returns a newWiredListcontaining 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
WiredListcontaining the specified elements
-
of
Returns a newWiredListcontaining 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
WiredListcontaining the specified elements
-
ofElements
Returns a newWiredListcontaining 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
WiredListcontaining the specified elements
-
join
Concatenates the providedWiredListinstances. This is a destructive operation for theWiredListinstances in the providedList. They will be empty when the method returns.- Type Parameters:
E- the type of the elements in the list- Parameters:
lists- theWiredListinstances to concatenate- Returns:
- a new
WiredListcontaining the elements in the individualWiredListinstances - 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'stestmethod.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:
trueif this list contained the specified element
-
removeIf
Removes all 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
-
first
Returns the first element of the list. ANoSuchElementExceptionis thrown if the list is empty.- Returns:
- the first element of the list
-
last
Returns the last element of the list. ANoSuchElementExceptionis 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 thisWiredList.- 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>= 0and<= list.size(). Specifying 0 (zero) is equivalent toprepend(value). Specifyinglist.size()is equivalent toappend(valueandadd(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. ANoSuchElementExceptionis thrown if the list is empty.- Returns:
- this instance
-
removeLast
Removes the last element from the list. ANoSuchElementExceptionis 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 betweenfromIndexandtoIndexwith 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 betweenfromIndexandtoIndexwith 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, usereplace.- 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 thisWiredList. Changes made to the copy will not propagate to this instance, and vice versa.- Returns:
- a deep copy of this
WiredList
-
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. IftoIndexis 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 this 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 toinsertAllandaddAll, 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, useinsertAlloraddAll.- Parameters:
index- the index at which to embed the listother- the list to embed- 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 instance
-
exchange
public WiredList<E> exchange(int myFromIndex, int myToIndex, WiredList<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 WiredList<E> embed(int myIndex, WiredList<? 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
-
attach
Appends the specified list to this list. This method is functionally equivalentappendAllandaddAll, but more efficient. However, it will leave the specified list empty. If you don't want this to happen, useappendAlloraddAll.- 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
Listconstitutes a group. ThisWiredListis 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 thejoinmethod 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
WiredList<WiredList<E>>. If you don't care about the exact type of the returnedList, you can simply write:WiredList<String> wl = ...; List<List<String>> groups = wl.group(...);Otherwise use any combination of
ListandWiredListthat 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 thisWiredListinto multipleWiredListinstances of the specified size. The partitions are chopped off from theWiredListand then placed in a separateWiredList. The last element in the returned list-of-lists is thisWiredList, and it will now contain at mostsizeelements.The runtime type of the return value is
WiredList<WiredList<E>>. If you don't care about the exact type of the returnedList, you can simply write:WiredList<String> wl = ...; List<List<String>> partitions = wl.partition(3);Otherwise use any combination of
ListandWiredListthat 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
WiredListinstances of the specified size
-
split
Splits thisWiredListinto the specified number of equally-sizedWiredListinstances. The last element in the returned list-of-lists is thisWiredList, and it will contain the remainder of the elements after dividing the list size bynumPartitions. The runtime type of the return value isWiredList<WiredList<E>>. If you don't care about the exact type of the returnedList, you can simply write:WiredList<String> wl = ...; List<List<String>> partitions = wl.split(3);Otherwise use any combination of
ListandWiredListthat suits your needs.- Type Parameters:
L0- the type of the lists within the returned listL1- the type of returned list- Parameters:
numPartitions- The number ofWiredListinstances to split thisWiredListinto- Returns:
- a list containing the specified number of
WiredListinstances
-
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
WiredListcontaining 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
WiredListcontaining all elements following the last element that does not satisfy the condition; possibly this instance
-
reverse
Reverses the order of the elements in thisWiredList.- 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 thesizeof 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 anIteratorthat traverses the list from the last element to the first. See alsoList.iterator().- Returns:
- an
Iteratorthat traverses the list from the last element to the first
-
wiredIterator
Returns aWiredIteratorthat traverses the list from the first element to the last.- Returns:
- a
WiredIteratorthat traverses the list from the first element to the last
-
wiredIterator
Returns aWiredIteratorthat 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
WiredIteratorthat 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 aWiredListare structural changes.WiredListdoes provide a method that returns a sublist (copySegment). 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 indexisuch 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 indexisuch thatObjects.equals(o, get(i)), or -1 if there is no such index.- Specified by:
lastIndexOfin 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:
getin 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:
addin interfaceCollection<E>- Specified by:
addin 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:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceList<E>- Parameters:
c- collection containing elements to be added to this list- Returns:
trueif 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_VALUEelements, returnsInteger.MAX_VALUE.- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Returns:
- the number of elements in this list
-
isEmpty
public boolean isEmpty()Returnstrueif this list contains no elements.- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceList<E>- Returns:
trueif this list contains no elements
-
contains
Returnstrueif this list contains the specified element. More formally, returnstrueif and only if this list contains at least one elementesuch thatObjects.equals(o, e).- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceList<E>- Parameters:
o- element whose presence in this list is to be tested- Returns:
trueif this list contains the specified element
-
containsAll
Returnstrueif this list contains all of the elements of the specified collection.- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceList<E>- Parameters:
c- collection to be checked for containment in this list- Returns:
trueif this list contains all of the elements of the specified collection- See Also:
-
removeAll
- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceList<E>
-
retainAll
- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceList<E>
-
iterator
Returns anIteratorthat 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:
listIteratorin 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 topreviouswould return the element with the specified index minus one.- Specified by:
listIteratorin 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. Returnstrueif 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 elementse1ande2are 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 theListinterface. -
hashCode
public int hashCode()Returns the hash code value for this list. -
toString
Returns aStringrepresentation of this list. -
toArray
Returns an array containing all elements in this list in proper sequence (from first to last element).- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin 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:
toArrayin interfaceCollection<E>- Specified by:
toArrayin 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
-