Class FXCollections
- javafx.collections.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
All MethodsStatic MethodsConcrete Methods Modifier and Type Method and Description static <E> ObservableList<E>checkedObservableList(ObservableList<E> list, Class<E> type)Creates and returns a typesafe wrapper on top of provided observable list.static <K,V> ObservableMap<K,V>checkedObservableMap(ObservableMap<K,V> map, Class<K> keyType, Class<V> valueType)Creates and returns a typesafe wrapper on top of provided observable map.static <E> ObservableSet<E>checkedObservableSet(ObservableSet<E> set, Class<E> type)Creates and returns a typesafe wrapper on top of provided observable set.static <E> ObservableList<E>concat(ObservableList<E>... lists)Concatenates more observable lists into one.static <T> voidcopy(ObservableList<? super T> dest, List<? extends T> src)Copies elements from src to dest.static <E> ObservableList<E>emptyObservableList()Creates and empty unmodifiable observable list.static <K,V> ObservableMap<K,V>emptyObservableMap()Creates and empty unmodifiable observable map.static <E> ObservableSet<E>emptyObservableSet()Creates and empty unmodifiable observable set.static <T> voidfill(ObservableList<? super T> list, T obj)Fills the provided list with obj.static <E> ObservableList<E>observableArrayList()Creates a new empty observable list that is backed by an arraylist.static <E> ObservableList<E>observableArrayList(Callback<E,Observable[]> extractor)Creates a new empty observable list backed by an arraylist.static <E> ObservableList<E>observableArrayList(Collection<? extends E> col)Creates a new observable array list and adds a content of collectioncolto it.static <E> ObservableList<E>observableArrayList(E... items)Creates a new observable array list withitemsadded to it.static ObservableFloatArrayobservableFloatArray()Creates a new empty observable float array.static ObservableFloatArrayobservableFloatArray(float... values)Creates a new observable float array withvaluesset to it.static ObservableFloatArrayobservableFloatArray(ObservableFloatArray array)Creates a new observable float array with copy of elements in givenarray.static <K,V> ObservableMap<K,V>observableHashMap()Creates a new empty observable map that is backed by a HashMap.static ObservableIntegerArrayobservableIntegerArray()Creates a new empty observable integer array.static ObservableIntegerArrayobservableIntegerArray(int... values)Creates a new observable integer array withvaluesset to it.static ObservableIntegerArrayobservableIntegerArray(ObservableIntegerArray array)Creates a new observable integer array with copy of elements in givenarray.static <E> ObservableList<E>observableList(List<E> list)Constructs an ObservableList that is backed by the specified list.static <E> ObservableList<E>observableList(List<E> list, Callback<E,Observable[]> extractor)Constructs an ObservableList that is backed by the specified list.static <K,V> ObservableMap<K,V>observableMap(Map<K,V> map)Constructs an ObservableMap that is backed by the specified map.static <E> ObservableSet<E>observableSet(E... elements)Constructs an ObservableSet backed by a HashSet that contains all the specified elements.static <E> ObservableSet<E>observableSet(Set<E> set)Constructs an ObservableSet that is backed by the specified set.static <T> booleanreplaceAll(ObservableList<T> list, T oldVal, T newVal)Replace all oldVal elements in the list with newVal element.static voidreverse(ObservableList list)Reverse the order in the list Fires only one change notification on the list.static voidrotate(ObservableList list, int distance)Rotates the list by distance.static voidshuffle(ObservableList<?> list)Shuffles all elements in the observable list.static voidshuffle(ObservableList list, Random rnd)Shuffles all elements in the observable list.static <E> ObservableList<E>singletonObservableList(E e)Creates an unmodifiable observable list with single element.static <T extends Comparable<? super T>>
voidsort(ObservableList<T> list)Sorts the provided observable list.static <T> voidsort(ObservableList<T> list, Comparator<? super T> c)Sorts the provided observable list using the c comparator.static <E> ObservableList<E>synchronizedObservableList(ObservableList<E> list)Creates and returns a synchronized wrapper on top of provided observable list.static <K,V> ObservableMap<K,V>synchronizedObservableMap(ObservableMap<K,V> map)Creates and returns a synchronized wrapper on top of provided observable map.static <E> ObservableSet<E>synchronizedObservableSet(ObservableSet<E> set)Creates and returns a synchronized wrapper on top of provided observable set.static <E> ObservableList<E>unmodifiableObservableList(ObservableList<E> list)Creates and returns unmodifiable wrapper list on top of provided observable list.static <K,V> ObservableMap<K,V>unmodifiableObservableMap(ObservableMap<K,V> map)Constructs a read-only interface to the specified ObservableMap.static <E> ObservableSet<E>unmodifiableObservableSet(ObservableSet<E> set)Creates and returns unmodifiable wrapper on top of provided observable set.
-
Method Detail
-
observableList
public static <E> ObservableList<E> observableList(List<E> list)
Constructs an ObservableList that is backed by the specified list. Mutation operations on the ObservableList instance will be reported to observers that have registered on that instance.
Note that mutation operations made directly to the underlying list are not reported to observers of any ObservableList that wraps it.Parameters:
list- a concrete List that backs this ObservableListReturns:
a newly created ObservableList
-
observableList
public static <E> ObservableList<E> observableList(List<E> list, Callback<E,Observable[]> extractor)Constructs an ObservableList that is backed by the specified list. Mutation operations on the ObservableList instance will be reported to observers that have registered on that instance.
Note that mutation operations made directly to the underlying list are not reported to observers of any ObservableList that wraps it.
This list also reports mutations of the elements in it by usingextractor. Observable objects returned by extractor (applied to each list element) are listened for changes and transformed into "update" change of ListChangeListener.Parameters:
list- a concrete List that backs this ObservableListReturns:
a newly created ObservableList
Since:
JavaFX 2.1
-
observableMap
public static <K,V> ObservableMap<K,V> observableMap(Map<K,V> map)
Constructs an ObservableMap that is backed by the specified map. Mutation operations on the ObservableMap instance will be reported to observers that have registered on that instance.
Note that mutation operations made directly to the underlying map are not reported to observers of any ObservableMap that wraps it.Parameters:
map- a Map that backs this ObservableMapReturns:
a newly created ObservableMap
-
observableSet
public static <E> ObservableSet<E> observableSet(Set<E> set)
Constructs an ObservableSet that is backed by the specified set. Mutation operations on the ObservableSet instance will be reported to observers that have registered on that instance.
Note that mutation operations made directly to the underlying set are not reported to observers of any ObservableSet that wraps it.Parameters:
set- a Set that backs this ObservableSetReturns:
a newly created ObservableSet
Since:
JavaFX 2.1
-
observableSet
public static <E> ObservableSet<E> observableSet(E... elements)
Constructs an ObservableSet backed by a HashSet that contains all the specified elements.Parameters:
elements- elements that will be added into returned ObservableSetReturns:
a newly created ObservableSet
Since:
JavaFX 2.1
-
unmodifiableObservableMap
public static <K,V> ObservableMap<K,V> unmodifiableObservableMap(ObservableMap<K,V> map)
Constructs a read-only interface to the specified ObservableMap. Only mutation operations made to the underlying ObservableMap will be reported to observers that have registered on the unmodifiable instance. This allows clients to track changes in a Map but disallows the ability to modify it.Parameters:
map- an ObservableMap that is to be monitored by this interfaceReturns:
a newly created UnmodifiableObservableMap
-
checkedObservableMap
public static <K,V> ObservableMap<K,V> checkedObservableMap(ObservableMap<K,V> map, Class<K> keyType, Class<V> valueType)Creates and returns a typesafe wrapper on top of provided observable map.Parameters:
map- an Observable map to be wrappedReturns:
a dynamically typesafe view of the specified map
Since:
JavaFX 8.0
See Also:
Collections#checkedMap(java.util.Map, java.lang.Class)
-
synchronizedObservableMap
public static <K,V> ObservableMap<K,V> synchronizedObservableMap(ObservableMap<K,V> map)
Creates and returns a synchronized wrapper on top of provided observable map.Parameters:
map- the map to be "wrapped" in a synchronized map.Returns:
A synchronized version of the observable map
Since:
JavaFX 8.0
-
emptyObservableMap
public static <K,V> ObservableMap<K,V> emptyObservableMap()
Creates and empty unmodifiable observable map.
-
observableIntegerArray
public static ObservableIntegerArray observableIntegerArray()
Creates a new empty observable integer array.Returns:
a newly created ObservableIntegerArray
Since:
JavaFX 8.0
-
observableIntegerArray
public static ObservableIntegerArray observableIntegerArray(int... values)
Creates a new observable integer array withvaluesset to it.Parameters:
values- the values that will be in the new observable integer arrayReturns:
a newly created ObservableIntegerArray
Since:
JavaFX 8.0
-
observableIntegerArray
public static ObservableIntegerArray observableIntegerArray(ObservableIntegerArray array)
Creates a new observable integer array with copy of elements in givenarray.Parameters:
array- observable integer array to copyReturns:
a newly created ObservableIntegerArray
Since:
JavaFX 8.0
-
observableFloatArray
public static ObservableFloatArray observableFloatArray()
Creates a new empty observable float array.Returns:
a newly created ObservableFloatArray
Since:
JavaFX 8.0
-
observableFloatArray
public static ObservableFloatArray observableFloatArray(float... values)
Creates a new observable float array withvaluesset to it.Parameters:
values- the values that will be in the new observable float arrayReturns:
a newly created ObservableFloatArray
Since:
JavaFX 8.0
-
observableFloatArray
public static ObservableFloatArray observableFloatArray(ObservableFloatArray array)
Creates a new observable float array with copy of elements in givenarray.Parameters:
array- observable float array to copyReturns:
a newly created ObservableFloatArray
Since:
JavaFX 8.0
-
observableArrayList
public static <E> ObservableList<E> observableArrayList()
Creates a new empty observable list that is backed by an arraylist.Returns:
a newly created ObservableList
See Also:
-
observableArrayList
public static <E> ObservableList<E> observableArrayList(Callback<E,Observable[]> extractor)
Creates a new empty observable list backed by an arraylist. This list reports element updates.Parameters:
extractor- element to Observable[] convertor. Observable objects are listened for changes on the element.Returns:
a newly created ObservableList
Since:
JavaFX 2.1
-
observableArrayList
public static <E> ObservableList<E> observableArrayList(E... items)
Creates a new observable array list withitemsadded to it.Parameters:
items- the items that will be in the new observable ArrayListReturns:
a newly created observableArrayList
See Also:
-
observableArrayList
public static <E> ObservableList<E> observableArrayList(Collection<? extends E> col)
Creates a new observable array list and adds a content of collectioncolto it.Parameters:
col- a collection which content should be added to the observableArrayListReturns:
a newly created observableArrayList
-
observableHashMap
public static <K,V> ObservableMap<K,V> observableHashMap()
Creates a new empty observable map that is backed by a HashMap.Type Parameters:
K- the type of keysReturns:
a newly created observable HashMap
-
concat
public static <E> ObservableList<E> concat(ObservableList<E>... lists)
Concatenates more observable lists into one. The resulting list would be backed by an arraylist.Parameters:
lists- lists to concatenateReturns:
new observable array list concatenated from the arguments
-
unmodifiableObservableList
public static <E> ObservableList<E> unmodifiableObservableList(ObservableList<E> list)
Creates and returns unmodifiable wrapper list on top of provided observable list.Parameters:
list- an ObservableList that is to be wrappedReturns:
an ObserableList wrapper that is unmodifiable
-
checkedObservableList
public static <E> ObservableList<E> checkedObservableList(ObservableList<E> list, Class<E> type)Creates and returns a typesafe wrapper on top of provided observable list.Parameters:
list- an Observable list to be wrappedReturns:
a dynamically typesafe view of the specified list
-
synchronizedObservableList
public static <E> ObservableList<E> synchronizedObservableList(ObservableList<E> list)
Creates and returns a synchronized wrapper on top of provided observable list.Parameters:
list- the list to be "wrapped" in a synchronized list.Returns:
A synchronized version of the observable list
-
emptyObservableList
public static <E> ObservableList<E> emptyObservableList()
Creates and empty unmodifiable observable list.Returns:
An empty unmodifiable observable list
See Also:
-
singletonObservableList
public static <E> ObservableList<E> singletonObservableList(E e)
Creates an unmodifiable observable list with single element.Parameters:
e- the only elements that will be contained in this singleton observable listReturns:
a singleton observable list
-
unmodifiableObservableSet
public static <E> ObservableSet<E> unmodifiableObservableSet(ObservableSet<E> set)
Creates and returns unmodifiable wrapper on top of provided observable set.Parameters:
set- an ObservableSet that is to be wrappedReturns:
an ObserableSet wrapper that is unmodifiable
Since:
JavaFX 8.0
-
checkedObservableSet
public static <E> ObservableSet<E> checkedObservableSet(ObservableSet<E> set, Class<E> type)Creates and returns a typesafe wrapper on top of provided observable set.Parameters:
set- an Observable set to be wrappedReturns:
a dynamically typesafe view of the specified set
Since:
JavaFX 8.0
-
synchronizedObservableSet
public static <E> ObservableSet<E> synchronizedObservableSet(ObservableSet<E> set)
Creates and returns a synchronized wrapper on top of provided observable set.Parameters:
set- the set to be "wrapped" in a synchronized set.Returns:
A synchronized version of the observable set
Since:
JavaFX 8.0
-
emptyObservableSet
public static <E> ObservableSet<E> emptyObservableSet()
Creates and empty unmodifiable observable set.
-
copy
public static <T> void copy(ObservableList<? super T> dest, List<? extends T> src)Copies elements from src to dest. Fires only one change notification on dest.Parameters:
dest- the destination observable list
-
fill
public static <T> void fill(ObservableList<? super T> list, T obj)Fills the provided list with obj. Fires only one change notification on the list.Parameters:
list- the list to fill
-
replaceAll
public static <T> boolean replaceAll(ObservableList<T> list, T oldVal, T newVal)Replace all oldVal elements in the list with newVal element. Fires only one change notification on the list.Parameters:
list- the list which will have it's elements replacedReturns:
true if the list was modified
-
reverse
public static void reverse(ObservableList list)
Reverse the order in the list Fires only one change notification on the list.Parameters:
list- the list to be reversedSee Also:
-
rotate
public static void rotate(ObservableList list, int distance)Rotates the list by distance. Fires only one change notification on the list.Parameters:
list- the list to be rotatedSee Also:
-
shuffle
public static void shuffle(ObservableList<?> list)
Shuffles all elements in the observable list. Fires only one change notification on the list.Parameters:
list- the list to shuffleSee Also:
-
shuffle
public static void shuffle(ObservableList list, Random rnd)Shuffles all elements in the observable list. Fires only one change notification on the list.Parameters:
list- the list to be shuffled
-
sort
public static <T extends Comparable<? super T>> void sort(ObservableList<T> list)
Sorts the provided observable list. Fires only one change notification on the list.See Also:
-
sort
public static <T> void sort(ObservableList<T> list, Comparator<? super T> c)Sorts the provided observable list using the c comparator. Fires only one change notification on the list.Parameters:
list- the list to sort
-
© 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.