Class FXCollections
public class FXCollections extends Object
The wrapper methods (like synchronizedObservableList or emptyObservableList) has exactly the same functionality as the methods in Collections, with exception that they return ObservableList and are therefore suitable for methods that require ObservableList on input.
The utility methods are here mainly for performance reasons. All methods are optimized in a way that they yield only limited number of notifications. On the other hand, java.util.Collections methods might call "modification methods" on an ObservableList multiple times, resulting in a number of notifications.
- Since:
- JavaFX 2.0
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
static <E> ObservableList |
checkedObservableList |
Creates and returns a typesafe wrapper on top of provided observable list. |
static <K, |
checkedObservableMap |
Creates and returns a typesafe wrapper on top of provided observable map. |
static <E> ObservableSet |
checkedObservableSet |
Creates and returns a typesafe wrapper on top of provided observable set. |
static <E> ObservableList |
concat |
Concatenates more observable lists into one. |
static <T> void |
copy |
Copies elements from src to dest. |
static <E> ObservableList |
emptyObservableList() |
Creates an empty unmodifiable observable list. |
static <K, |
emptyObservableMap() |
Creates an empty unmodifiable observable map. |
static <E> ObservableSet |
emptyObservableSet() |
Creates an empty unmodifiable observable set. |
static <T> void |
fill |
Fills the provided list with obj. |
static <E> ObservableList |
observableArrayList() |
Creates a new empty observable list that is backed by an array list. |
static <E> ObservableList |
observableArrayList |
Creates a new observable array list with items added to it. |
static <E> ObservableList |
observableArrayList |
Creates a new observable array list and adds a content of collection col to it. |
static <E> ObservableList |
observableArrayList |
Creates a new empty ObservableList that is backed by an array list and listens to changes in observables of its items. |
static ObservableFloatArray |
observableFloatArray() |
Creates a new empty observable float array. |
static ObservableFloatArray |
observableFloatArray |
Creates a new observable float array with values set to it. |
static ObservableFloatArray |
observableFloatArray |
Creates a new observable float array with copy of elements in given array. |
static <K, |
observableHashMap() |
Creates a new empty observable map that is backed by a HashMap. |
static ObservableIntegerArray |
observableIntegerArray() |
Creates a new empty observable integer array. |
static ObservableIntegerArray |
observableIntegerArray |
Creates a new observable integer array with values set to it. |
static ObservableIntegerArray |
observableIntegerArray |
Creates a new observable integer array with copy of elements in given array. |
static <E> ObservableList |
observableList |
Constructs an ObservableList that is backed by the specified list. |
static <E> ObservableList |
observableList |
Constructs an ObservableList that is backed by the specified list and listens to changes in observables of its items. |
static <K, |
observableMap |
Constructs an ObservableMap that is backed by the specified map. |
static <E> ObservableSet |
observableSet |
Constructs an ObservableSet backed by a HashSet that contains all the specified elements. |
static <E> ObservableSet |
observableSet |
Constructs an ObservableSet that is backed by the specified set. |
static <T> boolean |
replaceAll |
Replace all oldVal elements in the list with newVal element. |
static void |
reverse |
Reverses the order in the list. |
static void |
rotate |
Rotates the list by distance. |
static void |
shuffle |
Shuffles all elements in the observable list. |
static void |
shuffle |
Shuffles all elements in the observable list. |
static <E> ObservableList |
singletonObservableList |
Creates an unmodifiable observable list with single element. |
static <T extends Comparable<? super T>> |
sort |
Sorts the provided observable list as specified in Collections.sort(List). |
static <T> void |
sort |
Sorts the provided observable list as specified in Collections.sort(List, Comparator). |
static <E> ObservableList |
synchronizedObservableList |
Creates and returns a synchronized wrapper on top of provided observable list. |
static <K, |
synchronizedObservableMap |
Creates and returns a synchronized wrapper on top of provided observable map. |
static <E> ObservableSet |
synchronizedObservableSet |
Creates and returns a synchronized wrapper on top of provided observable set. |
static <E> ObservableList |
unmodifiableObservableList |
Creates and returns unmodifiable wrapper list on top of provided observable list. |
static <K, |
unmodifiableObservableMap |
Constructs a read-only interface to the specified ObservableMap. |
static <E> ObservableSet |
unmodifiableObservableSet |
Creates and returns unmodifiable wrapper on top of provided observable set. |
Method Details
observableList
public static <E> ObservableList<E> observableList(List<E> list)
Note that mutation operations made directly to the underlying list are not reported to observers of any ObservableList that wraps it.
- Type Parameters:
-
E- The type of List to be wrapped - Parameters:
-
list- a concrete List that backs this ObservableList - Returns:
- a newly created ObservableList
observableList
public static <E> ObservableList<E> observableList(List<E> list, Callback<E,Observable[]> extractor)
ObservableList that is backed by the specified list and listens to changes in observables of its items. Mutation operations made directly to the underlying list are not reported to observers of any ObservableList that wraps it. The extractor returns observables (usually properties) of the objects in the created list. These observables are listened for changes, and the user is notified of these through an update change of an attached ListChangeListener. These changes are unrelated to the changes made to the observable list itself using methods such as add and remove.
For example, a list of Shapes can listen to changes in the shapes' fill property.
- Type Parameters:
-
E- The type ofListto be wrapped - Parameters:
-
list- a concreteListthat backs thisObservableList -
extractor- element toObservable[]converter - Returns:
- a newly created
ObservableList - Since:
- JavaFX 2.1
- See Also:
observableMap
public static <K, V> ObservableMap<K,V> observableMap(Map<K,V> map)
Note that mutation operations made directly to the underlying map are not reported to observers of any ObservableMap that wraps it.
- Type Parameters:
-
K- the type of the wrapped key -
V- the type of the wrapped value - Parameters:
-
map- a Map that backs this ObservableMap - Returns:
- a newly created ObservableMap
observableSet
public static <E> ObservableSet<E> observableSet(Set<E> set)
Note that mutation operations made directly to the underlying set are not reported to observers of any ObservableSet that wraps it.
- Type Parameters:
-
E- The type of List to be wrapped - Parameters:
-
set- a Set that backs this ObservableSet - Returns:
- a newly created ObservableSet
- Since:
- JavaFX 2.1
observableSet
public static <E> ObservableSet<E> observableSet(E... elements)
- Type Parameters:
-
E- The type of List to be wrapped - Parameters:
-
elements- elements that will be added into returned ObservableSet - Returns:
- a newly created ObservableSet
- Since:
- JavaFX 2.1
unmodifiableObservableMap
public static <K, V> ObservableMap<K,V> unmodifiableObservableMap(ObservableMap<K,V> map)
- Type Parameters:
-
K- the type of the wrapped key -
V- the type of the wrapped value - Parameters:
-
map- an ObservableMap that is to be monitored by this interface - Returns:
- a newly created UnmodifiableObservableMap
checkedObservableMap
public static <K, V> ObservableMap<K,V> checkedObservableMap(ObservableMap<K,V> map, Class<K> keyType, Class<V> valueType)
- Type Parameters:
-
K- the type of the wrapped key -
V- the type of the wrapped value - Parameters:
-
map- an Observable map to be wrapped -
keyType- the type of key thatmapis permitted to hold -
valueType- the type of value thatmapis permitted to hold - Returns:
- a dynamically typesafe view of the specified map
- Since:
- JavaFX 8.0
- See Also:
synchronizedObservableMap
public static <K, V> ObservableMap<K,V> synchronizedObservableMap(ObservableMap<K,V> map)
- Type Parameters:
-
K- the type of the wrapped key -
V- the type of the wrapped value - Parameters:
-
map- the map to be "wrapped" in a synchronized map. - Returns:
- A synchronized version of the observable map
- Since:
- JavaFX 8.0
- See Also:
emptyObservableMap
public static <K, V> ObservableMap<K,V> emptyObservableMap()
- Type Parameters:
-
K- the type of the wrapped key -
V- the type of the wrapped value - Returns:
- An empty unmodifiable observable map
- Since:
- JavaFX 8.0
- See Also:
observableIntegerArray
public static ObservableIntegerArray observableIntegerArray()
- Returns:
- a newly created ObservableIntegerArray
- Since:
- JavaFX 8.0
observableIntegerArray
public static ObservableIntegerArray observableIntegerArray(int... values)
values set to it.- Parameters:
-
values- the values that will be in the new observable integer array - Returns:
- a newly created ObservableIntegerArray
- Since:
- JavaFX 8.0
observableIntegerArray
public static ObservableIntegerArray observableIntegerArray(ObservableIntegerArray array)
array.- Parameters:
-
array- observable integer array to copy - Returns:
- a newly created ObservableIntegerArray
- Since:
- JavaFX 8.0
observableFloatArray
public static ObservableFloatArray observableFloatArray()
- Returns:
- a newly created ObservableFloatArray
- Since:
- JavaFX 8.0
observableFloatArray
public static ObservableFloatArray observableFloatArray(float... values)
values set to it.- Parameters:
-
values- the values that will be in the new observable float array - Returns:
- a newly created ObservableFloatArray
- Since:
- JavaFX 8.0
observableFloatArray
public static ObservableFloatArray observableFloatArray(ObservableFloatArray array)
array.- Parameters:
-
array- observable float array to copy - Returns:
- a newly created ObservableFloatArray
- Since:
- JavaFX 8.0
observableArrayList
public static <E> ObservableList<E> observableArrayList()
- Type Parameters:
-
E- The type of List to be wrapped - Returns:
- a newly created ObservableList
- See Also:
observableArrayList
public static <E> ObservableList<E> observableArrayList(Callback<E,Observable[]> extractor)
ObservableList that is backed by an array list and listens to changes in observables of its items. The extractor returns observables (usually properties) of the objects in the created list. These observables are listened for changes and the user is notified of these through an update change of an attached ListChangeListener. These changes are unrelated to the changes made to the observable list itself using methods such as add and remove.
For example, a list of Shapes can listen to changes in the shapes' fill property.
- Type Parameters:
-
E- The type ofListto be wrapped - Parameters:
-
extractor- element toObservable[]converter - Returns:
- a newly created
ObservableList - Since:
- JavaFX 2.1
- See Also:
observableArrayList
public static <E> ObservableList<E> observableArrayList(E... items)
items added to it.- Type Parameters:
-
E- The type of List to be wrapped - Parameters:
-
items- the items that will be in the new observable ArrayList - Returns:
- a newly created observableArrayList
- See Also:
observableArrayList
public static <E> ObservableList<E> observableArrayList(Collection<? extends E> col)
col to it.- Type Parameters:
-
E- The type of List to be wrapped - Parameters:
-
col- a collection which content should be added to the observableArrayList - Returns:
- a newly created observableArrayList
observableHashMap
public static <K, V> ObservableMap<K,V> observableHashMap()
- Type Parameters:
-
K- the type of the wrapped key -
V- the type of the wrapped value - Returns:
- a newly created observable HashMap
concat
public static <E> ObservableList<E> concat(ObservableList<E>... lists)
- Type Parameters:
-
E- The type of List to be wrapped - Parameters:
-
lists- lists to concatenate - Returns:
- new observable array list concatenated from the arguments
unmodifiableObservableList
public static <E> ObservableList<E> unmodifiableObservableList(ObservableList<E> list)
- Type Parameters:
-
E- The type of List to be wrapped - Parameters:
-
list- an ObservableList that is to be wrapped - Returns:
- an ObserableList wrapper that is unmodifiable
- See Also:
checkedObservableList
public static <E> ObservableList<E> checkedObservableList(ObservableList<E> list, Class<E> type)
- Type Parameters:
-
E- The type of List to be wrapped - Parameters:
-
list- an Observable list to be wrapped -
type- the type of element thatlistis permitted to hold - Returns:
- a dynamically typesafe view of the specified list
- See Also:
synchronizedObservableList
public static <E> ObservableList<E> synchronizedObservableList(ObservableList<E> list)
- Type Parameters:
-
E- The type of List to be wrapped - Parameters:
-
list- the list to be "wrapped" in a synchronized list. - Returns:
- A synchronized version of the observable list
- See Also:
emptyObservableList
public static <E> ObservableList<E> emptyObservableList()
- Type Parameters:
-
E- The type of List to be wrapped - Returns:
- An empty unmodifiable observable list
- See Also:
singletonObservableList
public static <E> ObservableList<E> singletonObservableList(E e)
- Type Parameters:
-
E- The type of List to be wrapped - Parameters:
-
e- the only elements that will be contained in this singleton observable list - Returns:
- a singleton observable list
- See Also:
unmodifiableObservableSet
public static <E> ObservableSet<E> unmodifiableObservableSet(ObservableSet<E> set)
- Type Parameters:
-
E- The type of List to be wrapped - Parameters:
-
set- an ObservableSet that is to be wrapped - Returns:
- an ObserableSet wrapper that is unmodifiable
- Since:
- JavaFX 8.0
- See Also:
checkedObservableSet
public static <E> ObservableSet<E> checkedObservableSet(ObservableSet<E> set, Class<E> type)
- Type Parameters:
-
E- The type of List to be wrapped - Parameters:
-
set- an Observable set to be wrapped -
type- the type of element thatsetis permitted to hold - Returns:
- a dynamically typesafe view of the specified set
- Since:
- JavaFX 8.0
- See Also:
synchronizedObservableSet
public static <E> ObservableSet<E> synchronizedObservableSet(ObservableSet<E> set)
- Type Parameters:
-
E- The type of List to be wrapped - Parameters:
-
set- the set to be "wrapped" in a synchronized set. - Returns:
- A synchronized version of the observable set
- Since:
- JavaFX 8.0
- See Also:
emptyObservableSet
public static <E> ObservableSet<E> emptyObservableSet()
- Type Parameters:
-
E- The type of List to be wrapped - Returns:
- An empty unmodifiable observable set
- Since:
- JavaFX 8.0
- See Also:
copy
public static <T> void copy(ObservableList<? super T> dest, List<? extends T> src)
- Type Parameters:
-
T- The type of List to be wrapped - Parameters:
-
dest- the destination observable list -
src- the source list - See Also:
fill
public static <T> void fill(ObservableList<? super T> list, T obj)
- Type Parameters:
-
T- The type of List to be wrapped - Parameters:
-
list- the list to fill -
obj- the object to fill the list with - See Also:
replaceAll
public static <T> boolean replaceAll(ObservableList<T> list, T oldVal, T newVal)
- Type Parameters:
-
T- The type of List to be wrapped - Parameters:
-
list- the list which will have it's elements replaced -
oldVal- the element that is going to be replace -
newVal- the replacement - Returns:
- true if the list was modified
- See Also:
reverse
public static void reverse(ObservableList list)
- Parameters:
-
list- the list to be reversed - See Also:
rotate
public static void rotate(ObservableList list, int distance)
- Parameters:
-
list- the list to be rotated -
distance- the distance of rotation - See Also:
shuffle
public static void shuffle(ObservableList<?> list)
- Parameters:
-
list- the list to shuffle - See Also:
shuffle
public static void shuffle(ObservableList list, Random rnd)
- Parameters:
-
list- the list to be shuffled -
rnd- the random generator used for shuffling - See Also:
sort
public static <T extends Comparable<? super T>> void sort(ObservableList<T> list)
Collections.sort(List). Fires only one change notification on the list.- Type Parameters:
-
T- the type of elements in this list - Parameters:
-
list- the list to be sorted
sort
public static <T> void sort(ObservableList<T> list, Comparator<? super T> comparator)
Collections.sort(List, Comparator). Fires only one change notification on the list.- Type Parameters:
-
T- the type of elements in this list - Parameters:
-
list- the list to sort -
comparator- the comparator to determine the order of the list. Anullvalue indicates that the elements' natural ordering should be used.
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.