# Interface ObservableArray<T extends ObservableArray<T>>

Type Parameters:
  `T` - actual array instance type

All Superinterfaces:
  `Observable`

All Known Subinterfaces:
  `ObservableFaceArray, ObservableFloatArray, ObservableIntegerArray`

All Known Implementing Classes:
  `ObservableArrayBase`

public interface ObservableArray<T extends ObservableArray<T>> extends 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 Type
  Method
  Description
  `void`
  `addListener(ArrayChangeListener<T> listener)`
  Add a listener to this observable array.
  `void`
  `clear()`
  Empties the array by resizing it to 0.
  `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`.
  `void`
  `removeListener(ArrayChangeListener<T> listener)`
  Tries to remove a listener from this observable array.
  `void`
  `resize(int size)`
  Sets new length of data in this array.
  `int`
  `size()`
  Retrieves length of data in this array.
  `void`
  `trimToSize()`
  Shrinks the capacity to the current size of data in the array.

  ### Methods declared in interface Observable

  `addListener, removeListener, subscribe`

- ## Method Details

  - ### addListener

    void addListener(ArrayChangeListener<T> listener)
    Add a listener to this observable array.
    Parameters:
      `listener` - the listener for listening to the array changes
    Throws:
      `NullPointerException` - if `listener` is `null`

  - ### removeListener

    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` - a listener to remove
    Throws:
      `NullPointerException` - if `listener` is `null`

  - ### resize

    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` - new length of data in this array
    Throws:
      `NegativeArraySizeException` - if size is negative

  - ### ensureCapacity

    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` - the capacity of this array

  - ### trimToSize

    void trimToSize()
    Shrinks the capacity to the current size of data in the array.

  - ### clear

    void clear()
    Empties the array by resizing it to 0. Capacity is not changed.
    See Also:
      - `trimToSize()`

  - ### size

    int size()
    Retrieves length of data in this array.
    Returns:
      length of data in this array