APIdia Launch Partner
Top Description Methods
javafx.collections

public Interface ObservableArray<T extends ObservableArray<T>>

extends Observable
Known Direct Subinterfaces
javafx.collections.ObservableFloatArray, javafx.collections.ObservableIntegerArray
Known Direct Implementers
javafx.collections.ObservableArrayBase
Type Parameters
<T>
actual array instance type
Imports
javafx.beans.Observable

ObservableArray is an array that allows listeners to track changes when they occur. In order to track changes, the internal array is encapsulated and there is no direct access available from the outside. Bulk operations are supported but they always do a copy of the data range. You can find them in subclasses as they deal with primitive arrays directly.

Implementations have both capacity, which is internal array length, and size. If size needs to be increased beyond capacity, the capacity increases to match that new size. Use trimToSize() method to shrink it.

Since
JavaFX 8.0
See Also
ArrayChangeListener

Method Summary

Modifier and TypeMethod and Description
public void
addListener(ArrayChangeListener<T>
the listener for listening to the array changes
listener
)

Add a listener to this observable array.

public void
clear()

Empties the array by resizing it to 0.

public void
ensureCapacity(int
the capacity of this array
capacity
)

Grows the capacity of this array if the current capacity is less than given capacity, does nothing if it already exceeds the capacity.

public void
removeListener(ArrayChangeListener<T>
a listener to remove
listener
)

Tries to remove a listener from this observable array.

public void
resize(int
new length of data in this array
size
)

Sets new length of data in this array.

public int

Returns:

length of data in this array
size
()

Retrieves length of data in this array.

public void
trimToSize()

Shrinks the capacity to the current size of data in the array.

Inherited from javafx.beans.Observable:
addListenerremoveListenersubscribe

Method Detail

addListenerback to summary
public void addListener(ArrayChangeListener<T> listener)

Add a listener to this observable array.

Parameters
listener:ArrayChangeListener<T>

the listener for listening to the array changes

Exceptions
NullPointerException:
if listener is null
clearback to summary
public void clear()

Empties the array by resizing it to 0. Capacity is not changed.

See Also
trimToSize()
ensureCapacityback to summary
public void ensureCapacity(int capacity)

Grows the capacity of this array if the current capacity is less than given capacity, does nothing if it already exceeds the capacity.

Parameters
capacity:int

the capacity of this array

removeListenerback to summary
public void removeListener(ArrayChangeListener<T> listener)

Tries to remove a listener from this observable array. If the listener is not attached to this array, nothing happens.

Parameters
listener:ArrayChangeListener<T>

a listener to remove

Exceptions
NullPointerException:
if listener is null
resizeback to summary
public void resize(int size)

Sets new length of data in this array. This method grows capacity if necessary but never shrinks it. Resulting array will contain existing data for indexes that are less than the current size and zeroes for indexes that are greater than the current size.

Parameters
size:int

new length of data in this array

Exceptions
NegativeArraySizeException:
if size is negative
sizeback to summary
public int size()

Retrieves length of data in this array.

Returns:int

length of data in this array

trimToSizeback to summary
public void trimToSize()

Shrinks the capacity to the current size of data in the array.