Top Description Fields Constructors Methods
org.hibernate.collection

public Class PersistentIdentifierBag

extends AbstractPersistentCollection
implements List
Class Inheritance
All Implemented Interfaces
java.util.List, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable
Imports
java.io.Serializable, java.sql.ResultSet, .SQLException, java.util.ArrayList, .Collection, .HashMap, .Iterator, .List, .ListIterator, .Map, org.hibernate.EntityMode, .HibernateException, org.hibernate.loader.CollectionAliases, org.hibernate.engine.SessionImplementor, org.hibernate.persister.collection.CollectionPersister, org.hibernate.type.Type

An IdentifierBag implements "bag" semantics more efficiently than a regular Bag by adding a synthetic identifier column to the table. This identifier is unique for all rows in the table, allowing very efficient updates and deletes. The value of the identifier is never exposed to the application.

IdentifierBags may not be used for a many-to-one association. Furthermore, there is no reason to use inverse="true".
Author
Gavin King

Field Summary

Modifier and TypeField and Description
protected Map<K, V>
protected List<E>
Inherited from org.hibernate.collection.AbstractPersistentCollection:
UNKNOWN

Constructor Summary

AccessConstructor and Description
public
public
public

Method Summary

Modifier and TypeMethod and Description
public boolean
add(Object
element to be appended to this list
o
)

Implements java.util.List.add.

Appends the specified element to the end of this list (optional operation).
public void
add(int
index at which the specified element is to be inserted
index
,
Object
element to be inserted
element
)

Implements java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation).
public boolean
addAll(int
index at which to insert the first element from the specified collection
index
,
Collection<E>
collection containing elements to be added to this list
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 boolean
addAll(Collection<E>
collection containing elements to be added to this list
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 void
afterRowInsert(CollectionPersister persister, Object entry, int i)

Overrides org.hibernate.collection.AbstractPersistentCollection.afterRowInsert.

Implements org.hibernate.collection.PersistentCollection.afterRowInsert.

Called after inserting a row, to fetch the natively generated id
private void
beforeAdd(int index)

public void
beforeInitialize(CollectionPersister
The underlying collection persister.
persister
,
int
The anticipated size of the collection after initilization is complete.
anticipatedSize
)

Implements org.hibernate.collection.PersistentCollection.beforeInitialize.

Called before any elements are read into the collection, allowing appropriate initializations to occur.
private void
beforeRemove(int index)

public void
clear()

Implements java.util.List.clear.

Removes all of the elements from this list (optional operation).
public boolean
contains(Object
element whose presence in this list is to be tested
o
)

Implements java.util.List.contains.

Returns true if this list contains the specified element.
public boolean
containsAll(Collection<E>
collection to be checked for containment in this list
c
)

Implements java.util.List.containsAll.

Returns true if this list contains all of the elements of the specified collection.
public Serializable
disassemble(CollectionPersister persister)

Implements org.hibernate.collection.PersistentCollection.disassemble.

Disassemble the collection, ready for the cache
public boolean
public Iterator<E>
entries(CollectionPersister persister)

Implements org.hibernate.collection.PersistentCollection.entries.

Iterate all collection entries, during update of the database
public boolean
entryExists(Object entry, int i)

Implements org.hibernate.collection.PersistentCollection.entryExists.

Does an element exist at this entry in the collection?
public boolean
equalsSnapshot(CollectionPersister persister)

Implements org.hibernate.collection.PersistentCollection.equalsSnapshot.

Does the current state exactly match the snapshot?
public Object
get(int
index of the element to return
index
)

Implements java.util.List.get.

Returns the element at the specified position in this list.
public Iterator<E>
getDeletes(CollectionPersister persister, boolean indexIsFormula)

Implements org.hibernate.collection.PersistentCollection.getDeletes.

Get all the elements that need deleting
public Object
getElement(Object entry)

Implements org.hibernate.collection.PersistentCollection.getElement.

Get the value of the given collection entry
public Object
public Object
getIndex(Object entry, int i, CollectionPersister
it was more elegant before we added this...
persister
)

Implements org.hibernate.collection.PersistentCollection.getIndex.

Get the index of the given collection entry
public Collection<E>
public Serializable
getSnapshot(CollectionPersister persister)

Implements org.hibernate.collection.PersistentCollection.getSnapshot.

Return a new snapshot of the current state of the collection
public Object
getSnapshotElement(Object entry, int i)

Implements org.hibernate.collection.PersistentCollection.getSnapshotElement.

Get the snapshot value of the given collection entry
public int
indexOf(Object
element to search for
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 void
initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner)

Implements org.hibernate.collection.PersistentCollection.initializeFromCache.

Read the state of the collection from a disassembled cached value
public boolean
isEmpty()

Implements java.util.List.isEmpty.

Returns true if this list contains no elements.
public boolean
public boolean
isWrapper(Object collection)

Implements org.hibernate.collection.PersistentCollection.isWrapper.

Is this the wrapper for the given underlying collection instance?
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
element to search for
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 of the first element to be returned from the list iterator (by a call to next)
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
needsInserting(Object entry, int i, Type elemType)

Implements org.hibernate.collection.PersistentCollection.needsInserting.

Do we need to insert this element?
public boolean
needsUpdating(Object entry, int i, Type elemType)

Implements org.hibernate.collection.PersistentCollection.needsUpdating.

Do we need to update this element?
public void
preInsert(CollectionPersister persister)

Overrides org.hibernate.collection.AbstractPersistentCollection.preInsert.

Implements org.hibernate.collection.PersistentCollection.preInsert.

Called before inserting rows, to ensure that any surrogate keys are fully generated
public Object
readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases descriptor, Object owner)

Implements org.hibernate.collection.PersistentCollection.readFrom.

Read a row from the JDBC result set
public boolean
remove(Object
element to be removed from this list, if present
o
)

Implements java.util.List.remove.

Removes the first occurrence of the specified element from this list, if it is present (optional operation).
public Object
remove(int
the index of the element to be removed
index
)

Implements java.util.List.remove.

Removes the element at the specified position in this list (optional operation).
public boolean
removeAll(Collection<E>
collection containing elements to be removed from this list
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<E>
collection containing elements to be retained in this list
c
)

Implements java.util.List.retainAll.

Retains only the elements in this list that are contained in the specified collection (optional operation).
public Object
set(int
index of the element to replace
index
,
Object
element to be stored at the specified position
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
low endpoint (inclusive) of the subList
fromIndex
,
int
high endpoint (exclusive) of the subList
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 Object[]
toArray(Object[]
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.
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.
Inherited from org.hibernate.collection.AbstractPersistentCollection:
afterInitializebeginReadclearDirtydirtyendReadforceInitializationgetCachedSizegetKeygetOrphansgetOwnergetQueuedOrphansgetRolegetSessiongetSnapshotgetStoredSnapshotgetValuehasQueuedOperationsidentityRemoveinitializeisClearQueueEnabledisDirectlyAccessibleisDirtyisOperationQueueEnabledisPutQueueEnabledisRowUpdatePossibleisUnreferencedneedsRecreateperformQueuedOperationspostActionqueuedAdditionIteratorqueueOperationreadreadElementByIndexreadElementExistencereadIndexExistencereadSizesetCurrentSessionsetDirectlyAccessiblesetInitializedsetOwnersetSnapshotunsetSessionwasInitializedwrite

Field Detail

identifiersback to summary
protected Map<K, V> identifiers
valuesback to summary
protected List<E> values

Constructor Detail

PersistentIdentifierBagback to summary
public PersistentIdentifierBag(SessionImplementor session)
PersistentIdentifierBagback to summary
public PersistentIdentifierBag()
PersistentIdentifierBagback to summary
public PersistentIdentifierBag(SessionImplementor session, Collection<E> coll)

Method Detail

addback to summary
public boolean add(Object o)

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.

Parameters
o:Object

element to be appended to this list

Returns:boolean

true (as specified by Collection#add)

addback to summary
public void add(int index, Object 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).

Parameters
index:int

index at which the specified element is to be inserted

element:Object

element to be inserted

addAllback to summary
public boolean addAll(int index, Collection<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.)

Parameters
index:int

index at which to insert the first element from the specified collection

c:Collection<E>

collection containing elements to be added to this list

Returns:boolean

true if this list changed as a result of the call

addAllback to summary
public boolean addAll(Collection<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.)

Parameters
c:Collection<E>

collection containing elements to be added to this list

Returns:boolean

true if this list changed as a result of the call

afterRowInsertback to summary
public void afterRowInsert(CollectionPersister persister, Object entry, int i) throws HibernateException

Overrides org.hibernate.collection.AbstractPersistentCollection.afterRowInsert.

Implements org.hibernate.collection.PersistentCollection.afterRowInsert.

Doc from org.hibernate.collection.AbstractPersistentCollection.afterRowInsert.

Called after inserting a row, to fetch the natively generated id

beforeAddback to summary
private void beforeAdd(int index)
beforeInitializeback to summary
public void beforeInitialize(CollectionPersister persister, int anticipatedSize)

Implements org.hibernate.collection.PersistentCollection.beforeInitialize.

Doc from org.hibernate.collection.PersistentCollection.beforeInitialize.

Called before any elements are read into the collection, allowing appropriate initializations to occur.

Parameters
persister:CollectionPersister

The underlying collection persister.

anticipatedSize:int

The anticipated size of the collection after initilization is complete.

beforeRemoveback to summary
private void beforeRemove(int index)
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.

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).

Parameters
o:Object

element whose presence in this list is to be tested

Returns:boolean

true if this list contains the specified element

containsAllback to summary
public boolean containsAll(Collection<E> 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.

Parameters
c:Collection<E>

collection to be checked for containment in this list

Returns:boolean

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

disassembleback to summary
public Serializable disassemble(CollectionPersister persister) throws HibernateException

Implements org.hibernate.collection.PersistentCollection.disassemble.

Doc from org.hibernate.collection.PersistentCollection.disassemble.

Disassemble the collection, ready for the cache

emptyback to summary
public boolean empty()

Implements abstract org.hibernate.collection.AbstractPersistentCollection.empty.

Implements org.hibernate.collection.PersistentCollection.empty.

Doc from org.hibernate.collection.AbstractPersistentCollection.empty.

Is the initialized collection empty?

entriesback to summary
public Iterator<E> entries(CollectionPersister persister)

Implements org.hibernate.collection.PersistentCollection.entries.

Doc from org.hibernate.collection.PersistentCollection.entries.

Iterate all collection entries, during update of the database

entryExistsback to summary
public boolean entryExists(Object entry, int i)

Implements org.hibernate.collection.PersistentCollection.entryExists.

Doc from org.hibernate.collection.PersistentCollection.entryExists.

Does an element exist at this entry in the collection?

equalsSnapshotback to summary
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException

Implements org.hibernate.collection.PersistentCollection.equalsSnapshot.

Doc from org.hibernate.collection.PersistentCollection.equalsSnapshot.

Does the current state exactly match the snapshot?

getback to summary
public Object get(int index)

Implements java.util.List.get.

Doc from java.util.List.get.

Returns the element at the specified position in this list.

Parameters
index:int

index of the element to return

Returns:Object

the element at the specified position in this list

getDeletesback to summary
public Iterator<E> getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException

Implements org.hibernate.collection.PersistentCollection.getDeletes.

Doc from org.hibernate.collection.PersistentCollection.getDeletes.

Get all the elements that need deleting

getElementback to summary
public Object getElement(Object entry)

Implements org.hibernate.collection.PersistentCollection.getElement.

Doc from org.hibernate.collection.PersistentCollection.getElement.

Get the value of the given collection entry

getIdentifierback to summary
public Object getIdentifier(Object entry, int i)

Overrides org.hibernate.collection.AbstractPersistentCollection.getIdentifier.

Implements org.hibernate.collection.PersistentCollection.getIdentifier.

Doc from org.hibernate.collection.PersistentCollection.getIdentifier.

Get the index of the given collection entry

getIndexback to summary
public Object getIndex(Object entry, int i, CollectionPersister persister)

Implements org.hibernate.collection.PersistentCollection.getIndex.

Doc from org.hibernate.collection.PersistentCollection.getIndex.

Get the index of the given collection entry

Parameters
persister:CollectionPersister

it was more elegant before we added this...

getOrphansback to summary
public Collection<E> getOrphans(Serializable snapshot, String entityName) throws HibernateException

Implements abstract org.hibernate.collection.AbstractPersistentCollection.getOrphans.

Implements org.hibernate.collection.PersistentCollection.getOrphans.

Doc from org.hibernate.collection.AbstractPersistentCollection.getOrphans.

get all "orphaned" elements

getSnapshotback to summary
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException

Implements org.hibernate.collection.PersistentCollection.getSnapshot.

Doc from org.hibernate.collection.PersistentCollection.getSnapshot.

Return a new snapshot of the current state of the collection

getSnapshotElementback to summary
public Object getSnapshotElement(Object entry, int i)

Implements org.hibernate.collection.PersistentCollection.getSnapshotElement.

Doc from org.hibernate.collection.PersistentCollection.getSnapshotElement.

Get the snapshot value of the given collection entry

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.

Parameters
o:Object

element to search for

Returns:int

the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element

initializeFromCacheback to summary
public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) throws HibernateException

Implements org.hibernate.collection.PersistentCollection.initializeFromCache.

Doc from org.hibernate.collection.PersistentCollection.initializeFromCache.

Read the state of the collection from a disassembled cached value

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.

Returns:boolean

true if this list contains no elements

isSnapshotEmptyback to summary
public boolean isSnapshotEmpty(Serializable snapshot)

Implements org.hibernate.collection.PersistentCollection.isSnapshotEmpty.

Doc from org.hibernate.collection.PersistentCollection.isSnapshotEmpty.

Is the snapshot empty?

isWrapperback to summary
public boolean isWrapper(Object collection)

Implements org.hibernate.collection.PersistentCollection.isWrapper.

Doc from org.hibernate.collection.PersistentCollection.isWrapper.

Is this the wrapper for the given underlying collection instance?

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.

Returns:Iterator<E>

an iterator over the elements in this list in proper sequence

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.

Parameters
o:Object

element to search for

Returns:int

the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element

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).

Returns:ListIterator<E>

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

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.

Parameters
index:int

index of the first element to be returned from the list iterator (by a call to next)

Returns:ListIterator<E>

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

needsInsertingback to summary
public boolean needsInserting(Object entry, int i, Type elemType) throws HibernateException

Implements org.hibernate.collection.PersistentCollection.needsInserting.

Doc from org.hibernate.collection.PersistentCollection.needsInserting.

Do we need to insert this element?

needsUpdatingback to summary
public boolean needsUpdating(Object entry, int i, Type elemType) throws HibernateException

Implements org.hibernate.collection.PersistentCollection.needsUpdating.

Doc from org.hibernate.collection.PersistentCollection.needsUpdating.

Do we need to update this element?

preInsertback to summary
public void preInsert(CollectionPersister persister) throws HibernateException

Overrides org.hibernate.collection.AbstractPersistentCollection.preInsert.

Implements org.hibernate.collection.PersistentCollection.preInsert.

Doc from org.hibernate.collection.AbstractPersistentCollection.preInsert.

Called before inserting rows, to ensure that any surrogate keys are fully generated

readFromback to summary
public Object readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases descriptor, Object owner) throws HibernateException, SQLException

Implements org.hibernate.collection.PersistentCollection.readFrom.

Doc from org.hibernate.collection.PersistentCollection.readFrom.

Read a row from the JDBC result set

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).

Parameters
o:Object

element to be removed from this list, if present

Returns:boolean

true if this list contained the specified element

removeback to summary
public Object 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.

Parameters
index:int

the index of the element to be removed

Returns:Object

the element previously at the specified position

removeAllback to summary
public boolean removeAll(Collection<E> 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).

Parameters
c:Collection<E>

collection containing elements to be removed from this list

Returns:boolean

true if this list changed as a result of the call

retainAllback to summary
public boolean retainAll(Collection<E> 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.

Parameters
c:Collection<E>

collection containing elements to be retained in this list

Returns:boolean

true if this list changed as a result of the call

setback to summary
public Object set(int index, Object 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).

Parameters
index:int

index of the element to replace

element:Object

element to be stored at the specified position

Returns:Object

the element previously at the specified position

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.

Returns:int

the number of elements in this list

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.)

Parameters
fromIndex:int

low endpoint (inclusive) of the subList

toIndex:int

high endpoint (exclusive) of the subList

Returns:List<E>

a view of the specified range within this list

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.

Returns:Object[]

an array containing all of the elements in this list in proper sequence

toArrayback to summary
public Object[] toArray(Object[] 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().
Parameters
a:Object[]

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:Object[]

an array containing the elements of this list