APIdia Launch Partner
Top Description Inners Constructors Methods
javafx.collections

public abstract Class ModifiableObservableListBase<E>

extends ObservableListBase<E>
Class Inheritance
Known Direct Subclasses
com.sun.javafx.collections.ObservableListWrapper, com.sun.javafx.collections.ObservableSequentialListWrapper
Type Parameters
<E>
the type of the elements contained in the List
Imports
java.util.Collection, .Iterator, .List, .ListIterator, .Objects

Abstract class that serves as a base class for ObservableList implementations that are modifiable. To implement a modifiable ObservableList class, you just need to implement the following set of methods: and the notifications and built and fired automatically for you.

Example of a simple ObservableList delegating to another List would look like this:


  public class ArrayObservableList<E> extends ModifiableObservableList<E> {

  private final List<E> delegate = new ArrayList<>();

  public E get(int index) {
      return delegate.get(index);
  }

  public int size() {
      return delegate.size();
  }

  protected void doAdd(int index, E element) {
      delegate.add(index, element);
  }

  protected E doSet(int index, E element) {
      return delegate.set(index, element);
  }

  protected E doRemove(int index) {
      return delegate.remove(index);
  }

Since
JavaFX 8.0
See Also
ObservableListBase

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Constructor Summary

AccessConstructor and Description
public
ModifiableObservableListBase()

Creates a default ModifiableObservableListBase.

Method Summary

Modifier and TypeMethod and Description
public void
add(int index, E element)

Overrides java.util.AbstractList.add.

Implements java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation).

public boolean
addAll(Collection<? extends E> c)

Overrides java.util.AbstractCollection.addAll.

Implements java.util.List.addAll, java.util.Collection.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 (optional operation).

public boolean
addAll(int index, Collection<? extends E> c)

Overrides java.util.AbstractList.addAll.

Implements java.util.List.addAll.

Inserts all of the elements in the specified collection into this list at the specified position (optional operation).

protected abstract void
doAdd(int
the position where to add the element
index
,
E
the element that will be added
element
)

Adds the element to the List at the position of index.

protected abstract E

Returns:

the removed element
doRemove
(int
the index of the removed element
index
)

Removes the element at position of index.

protected abstract E

Returns:

the old element at the specified position
doSet
(int
the position where to set the element
index
,
E
the element that will be set at the specified position
element
)

Sets the element in the List at the position of index.

public abstract E
get(int index)

Redeclares java.util.List.get.

Implements abstract java.util.AbstractList.get.

Returns the element at the specified position in this list.

public boolean
remove(Object o)

Overrides java.util.AbstractCollection.remove.

Implements java.util.List.remove, java.util.Collection.remove.

Removes the first occurrence of the specified element from this list, if it is present (optional operation).

public E
remove(int index)

Overrides java.util.AbstractList.remove.

Implements java.util.List.remove.

Removes the element at the specified position in this list (optional operation).

public boolean
removeAll(Collection<?> c)

Overrides java.util.AbstractCollection.removeAll.

Implements java.util.List.removeAll, java.util.Collection.removeAll.

Removes from this list all of its elements that are contained in the specified collection (optional operation).

protected void
removeRange(int fromIndex, int toIndex)

Overrides java.util.AbstractList.removeRange.

Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive.

public boolean
replaceRange(int from, int to, Collection<? extends E> col)

Overrides default javafx.collections.ObservableList.replaceRange.

Replaces the elements in the range [from, to) with the elements from the given collection.

public boolean
retainAll(Collection<?> c)

Overrides java.util.AbstractCollection.retainAll.

Implements java.util.List.retainAll, java.util.Collection.retainAll.

Retains only the elements in this list that are contained in the specified collection (optional operation).

public E
set(int index, E element)

Overrides java.util.AbstractList.set.

Implements java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).

public boolean
setAll(Collection<? extends E> col)

Overrides javafx.collections.ObservableListBase.setAll.

Implements javafx.collections.ObservableList.setAll.

Clears the ObservableList and adds all elements from the collection.

public abstract int
size()

Redeclares java.util.List.size, java.util.Collection.size.

Implements abstract java.util.AbstractCollection.size.

Returns the number of elements in this list.

public List<E>
subList(int fromIndex, int toIndex)

Overrides java.util.AbstractList.subList.

Implements java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.

Inherited from javafx.collections.ObservableListBase:
addAlladdListeneraddListenerbeginChangeendChangefireChangehasListenersnextAddnextPermutationnextRemovenextRemovenextReplacenextSetnextUpdateremoveremoveAllremoveListenerremoveListenerretainAllsetAll

Constructor Detail

ModifiableObservableListBaseback to summary
public ModifiableObservableListBase()

Creates a default ModifiableObservableListBase.

Method Detail

addback to summary
public void add(int index, E element)

Overrides java.util.AbstractList.add.

Implements java.util.List.add.

Doc from java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Annotations
@Override
addAllback to summary
public boolean addAll(Collection<? extends E> c)

Overrides java.util.AbstractCollection.addAll.

Implements java.util.List.addAll, java.util.Collection.addAll.

Doc from java.util.List.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 (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)

Annotations
@Override
addAllback to summary
public boolean addAll(int index, Collection<? extends E> c)

Overrides java.util.AbstractList.addAll.

Implements java.util.List.addAll.

Doc from java.util.List.addAll.

Inserts all of the 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). The new elements will appear in 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. (Note that this will occur if the specified collection is this list, and it's nonempty.)

Annotations
@Override
doAddback to summary
protected abstract void doAdd(int index, E element)

Adds the element to the List at the position of index.

For the description of possible exceptions, please refer to the documentation of add(java.lang.Object) method.

Parameters
index:int

the position where to add the element

element:E

the element that will be added

Exceptions
ClassCastException:
if the type of the specified element is incompatible with this list
NullPointerException:
if the specified arguments contain one or more null elements
IllegalArgumentException:
if some property of this element prevents it from being added to this list
IndexOutOfBoundsException:
if the index is out of range (index < 0 || index > size())
doRemoveback to summary
protected abstract E doRemove(int index)

Removes the element at position of index.

Parameters
index:int

the index of the removed element

Returns:E

the removed element

Exceptions
IndexOutOfBoundsException:
if the index is out of range (index < 0 || index >= size())
doSetback to summary
protected abstract E doSet(int index, E element)

Sets the element in the List at the position of index.

For the description of possible exceptions, please refer to the documentation of set(int, java.lang.Object) method.

Parameters
index:int

the position where to set the element

element:E

the element that will be set at the specified position

Returns:E

the old element at the specified position

Exceptions
ClassCastException:
if the type of the specified element is incompatible with this list
NullPointerException:
if the specified arguments contain one or more null elements
IllegalArgumentException:
if some property of this element prevents it from being added to this list
IndexOutOfBoundsException:
if the index is out of range (index < 0 || index >= size())
getback to summary
public abstract E get(int index)

Redeclares java.util.List.get.

Implements abstract java.util.AbstractList.get.

Doc from java.util.List.get.

Returns the element at the specified position in this list.

Annotations
@Override
removeback to summary
public boolean remove(Object o)

Overrides java.util.AbstractCollection.remove.

Implements java.util.List.remove, java.util.Collection.remove.

Doc from java.util.List.remove.

Removes the first occurrence of the specified element from this list, if it is present (optional operation). If this list does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that Objects.equals(o, get(i)) (if such an element exists). Returns true if this list contained the specified element (or equivalently, if this list changed as a result of the call).

Annotations
@Override
removeback to summary
public E remove(int index)

Overrides java.util.AbstractList.remove.

Implements java.util.List.remove.

Doc from java.util.List.remove.

Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.

Annotations
@Override
removeAllback to summary
public boolean removeAll(Collection<?> c)

Overrides java.util.AbstractCollection.removeAll.

Implements java.util.List.removeAll, java.util.Collection.removeAll.

Doc from java.util.List.removeAll.

Removes from this list all of its elements that are contained in the specified collection (optional operation).

Annotations
@Override
removeRangeback to summary
protected void removeRange(int fromIndex, int toIndex)

Overrides java.util.AbstractList.removeRange.

Doc from java.util.AbstractList.removeRange.

Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the list by (toIndex - fromIndex) elements. (If toIndex==fromIndex, this operation has no effect.)

This method is called by the clear operation on this list and its subLists. Overriding this method to take advantage of the internals of the list implementation can substantially improve the performance of the clear operation on this list and its subLists.

Annotations
@Override
replaceRangeback to summary
public boolean replaceRange(int from, int to, Collection<? extends E> col)

Overrides default javafx.collections.ObservableList.replaceRange.

Doc from javafx.collections.ObservableList.replaceRange.

Replaces the elements in the range [from, to) with the elements from the given collection. The existing elements in the specified range are removed, and the new elements are inserted at position from.

If from == to, the range is empty and the elements from the given collection are inserted at position from.

Annotations
@Override
retainAllback to summary
public boolean retainAll(Collection<?> c)

Overrides java.util.AbstractCollection.retainAll.

Implements java.util.List.retainAll, java.util.Collection.retainAll.

Doc from java.util.List.retainAll.

Retains only the elements in this list that are contained in the specified collection (optional operation). In other words, removes from this list all of its elements that are not contained in the specified collection.

Annotations
@Override
setback to summary
public E set(int index, E element)

Overrides java.util.AbstractList.set.

Implements java.util.List.set.

Doc from java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).

Annotations
@Override
setAllback to summary
public boolean setAll(Collection<? extends E> col)

Overrides javafx.collections.ObservableListBase.setAll.

Implements javafx.collections.ObservableList.setAll.

Doc from javafx.collections.ObservableList.setAll.

Clears the ObservableList and adds all elements from the collection.

Annotations
@Override
sizeback to summary
public abstract int size()

Redeclares java.util.List.size, java.util.Collection.size.

Implements abstract java.util.AbstractCollection.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Annotations
@Override
subListback to summary
public List<E> subList(int fromIndex, int toIndex)

Overrides java.util.AbstractList.subList.

Implements java.util.List.subList.

Doc from java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are 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 supported by this list.

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 for indexOf and lastIndexOf, and all of the algorithms in the Collections class 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.)

Annotations
@Override
javafx.collections back to summary

pack-priv Class ModifiableObservableListBase.SubObservableList

extends Object
implements List<E>
Class Inheritance
  • java.lang.Object
  • javafx.collections.ModifiableObservableListBase.SubObservableList
All Implemented Interfaces
java.util.List, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable

Field Summary

Modifier and TypeField and Description
private List<E>

Constructor Summary

AccessConstructor and Description
public
SubObservableList(List<E> sublist)

Method Summary

Modifier and TypeMethod and Description
public boolean
add(E e)

Implements java.util.List.add.

Appends the specified element to the end of this list (optional operation).

public void
add(int index, E element)

Implements java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation).

public boolean
addAll(Collection<? extends E> c)

Implements java.util.List.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 (optional operation).

public boolean
addAll(int index, Collection<? extends E> c)

Implements java.util.List.addAll.

Inserts all of the elements in the specified collection into this list at the specified position (optional operation).

public void
clear()

Implements java.util.List.clear.

Removes all of the elements from this list (optional operation).

public boolean
contains(Object o)

Implements java.util.List.contains.

Returns true if this list contains the specified element.

public boolean
containsAll(Collection<?> c)

Implements java.util.List.containsAll.

Returns true if this list contains all of the elements of the specified collection.

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Implements java.util.List.equals.

Compares the specified object with this list for equality.

public E
get(int index)

Implements java.util.List.get.

Returns the element at the specified position in this list.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.List.hashCode.

Returns the hash code value for this list.

public int
indexOf(Object o)

Implements java.util.List.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.

public boolean
isEmpty()

Implements java.util.List.isEmpty.

Returns true if this list contains no elements.

public Iterator<E>
iterator()

Implements java.util.List.iterator.

Returns an iterator over the elements in this list in proper sequence.

public int
lastIndexOf(Object o)

Implements java.util.List.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.

public ListIterator<E>
listIterator()

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).

public ListIterator<E>
listIterator(int index)

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.

public boolean
remove(Object o)

Implements java.util.List.remove.

Removes the first occurrence of the specified element from this list, if it is present (optional operation).

public E
remove(int index)

Implements java.util.List.remove.

Removes the element at the specified position in this list (optional operation).

public boolean
removeAll(Collection<?> c)

Implements java.util.List.removeAll.

Removes from this list all of its elements that are contained in the specified collection (optional operation).

public boolean
retainAll(Collection<?> c)

Implements java.util.List.retainAll.

Retains only the elements in this list that are contained in the specified collection (optional operation).

public E
set(int index, E element)

Implements java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).

public int
size()

Implements java.util.List.size.

Returns the number of elements in this list.

public List<E>
subList(int fromIndex, int toIndex)

Implements java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.

public Object[]
toArray()

Implements java.util.List.toArray.

Returns an array containing all of the elements in this list in proper sequence (from first to last element).

public <T> T[]
toArray(T[] a)

Implements java.util.List.toArray.

Returns an array containing all of the 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.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

sublistback to summary
private List<E> sublist

Constructor Detail

SubObservableListback to summary
public SubObservableList(List<E> sublist)

Method Detail

addback to summary
public boolean add(E e)

Implements java.util.List.add.

Doc from java.util.List.add.

Appends the specified element to the end of this list (optional operation).

Lists that support this operation may place limitations on what elements may be added to this list. In particular, some lists will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. List classes should clearly specify in their documentation any restrictions on what elements may be added.

Annotations
@Override
addback to summary
public void add(int index, E element)

Implements java.util.List.add.

Doc from java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Annotations
@Override
addAllback to summary
public boolean addAll(Collection<? extends E> c)

Implements java.util.List.addAll.

Doc from java.util.List.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 (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)

Annotations
@Override
addAllback to summary
public boolean addAll(int index, Collection<? extends E> c)

Implements java.util.List.addAll.

Doc from java.util.List.addAll.

Inserts all of the 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). The new elements will appear in 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. (Note that this will occur if the specified collection is this list, and it's nonempty.)

Annotations
@Override
clearback to summary
public void clear()

Implements java.util.List.clear.

Doc from java.util.List.clear.

Removes all of the elements from this list (optional operation). The list will be empty after this call returns.

Annotations
@Override
containsback to summary
public boolean contains(Object o)

Implements java.util.List.contains.

Doc from java.util.List.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 Objects.equals(o, e).

Annotations
@Override
containsAllback to summary
public boolean containsAll(Collection<?> c)

Implements java.util.List.containsAll.

Doc from java.util.List.containsAll.

Returns true if this list contains all of the elements of the specified collection.

Annotations
@Override
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Implements java.util.List.equals.

Doc from java.util.List.equals.

Compares the specified object with this list for equality. Returns true 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 elements e1 and e2 are equal if Objects.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 the List interface.

Annotations
@Override
getback to summary
public E get(int index)

Implements java.util.List.get.

Doc from java.util.List.get.

Returns the element at the specified position in this list.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.List.hashCode.

Doc from java.util.List.hashCode.

Returns the hash code value for this list. The hash code of a list is defined to be the result of the following calculation:

int hashCode = 1;
    for (E e : list)
        hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
This ensures that list1.equals(list2) implies that list1.hashCode()==list2.hashCode() for any two lists, list1 and list2, as required by the general contract of Object#hashCode.
Annotations
@Override
indexOfback to summary
public int indexOf(Object o)

Implements java.util.List.indexOf.

Doc from java.util.List.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 Objects.equals(o, get(i)), or -1 if there is no such index.

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Implements java.util.List.isEmpty.

Doc from java.util.List.isEmpty.

Returns true if this list contains no elements.

Annotations
@Override
iteratorback to summary
public Iterator<E> iterator()

Implements java.util.List.iterator.

Doc from java.util.List.iterator.

Returns an iterator over the elements in this list in proper sequence.

Annotations
@Override
lastIndexOfback to summary
public int lastIndexOf(Object o)

Implements java.util.List.lastIndexOf.

Doc from java.util.List.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 Objects.equals(o, get(i)), or -1 if there is no such index.

Annotations
@Override
listIteratorback to summary
public ListIterator<E> listIterator()

Implements java.util.List.listIterator.

Doc from java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).

Annotations
@Override
listIteratorback to summary
public ListIterator<E> listIterator(int index)

Implements java.util.List.listIterator.

Doc from java.util.List.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 to next. An initial call to previous would return the element with the specified index minus one.

Annotations
@Override
removeback to summary
public boolean remove(Object o)

Implements java.util.List.remove.

Doc from java.util.List.remove.

Removes the first occurrence of the specified element from this list, if it is present (optional operation). If this list does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that Objects.equals(o, get(i)) (if such an element exists). Returns true if this list contained the specified element (or equivalently, if this list changed as a result of the call).

Annotations
@Override
removeback to summary
public E remove(int index)

Implements java.util.List.remove.

Doc from java.util.List.remove.

Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.

Annotations
@Override
removeAllback to summary
public boolean removeAll(Collection<?> c)

Implements java.util.List.removeAll.

Doc from java.util.List.removeAll.

Removes from this list all of its elements that are contained in the specified collection (optional operation).

Annotations
@Override
retainAllback to summary
public boolean retainAll(Collection<?> c)

Implements java.util.List.retainAll.

Doc from java.util.List.retainAll.

Retains only the elements in this list that are contained in the specified collection (optional operation). In other words, removes from this list all of its elements that are not contained in the specified collection.

Annotations
@Override
setback to summary
public E set(int index, E element)

Implements java.util.List.set.

Doc from java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).

Annotations
@Override
sizeback to summary
public int size()

Implements java.util.List.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Annotations
@Override
subListback to summary
public List<E> subList(int fromIndex, int toIndex)

Implements java.util.List.subList.

Doc from java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are 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 supported by this list.

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 for indexOf and lastIndexOf, and all of the algorithms in the Collections class 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.)

Annotations
@Override
toArrayback to summary
public Object[] toArray()

Implements java.util.List.toArray.

Doc from java.util.List.toArray.

Returns an array containing all of the elements in this list in proper sequence (from first to last element).

The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array even if this list is backed by an array). The caller is thus free to modify the returned array.

This method acts as bridge between array-based and collection-based APIs.

Annotations
@Override
toArrayback to summary
public <T> T[] toArray(T[] a)

Implements java.util.List.toArray.

Doc from java.util.List.toArray.

Returns an array containing all of the 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. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.

If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the list is set to null. (This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.)

Like the toArray() method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.

Suppose x is a list known to contain only strings. The following code can be used to dump the list into a newly allocated array of String:

String[] y = x.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to toArray().
Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override