Java Reference
In-Depth Information
void shuffle(ObservableList list, java.util.Random rnd)
void sort(ObservableList<T> list)
void sort(ObservableList<T> list, java.util.Comparator<? super T> c)
We illustrate the effects of these utility methods in Listing 7-6.
Listing 7-6. FXCollectionsExample.java
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;
public class FXCollectionsExample {
public static void main(String[] args) {
ObservableList<String> strings = FXCollections.observableArrayList();
strings.addListener(new MyListener());
System.out.println("Calling addAll(\"Zero\", \"One\", \"Two\", \"Three\"): ");
strings.addAll("Zero", "One", "Two", "Three");
System.out.println("Calling copy: ");
FXCollections.copy(strings, Arrays.asList("Four", "Five"));
System.out.println("Calling replaceAll: ");
FXCollections.replaceAll(strings, "Two", "Two_1");
System.out.println("Calling reverse: ");
FXCollections.reverse(strings);
System.out.println("Calling rotate(strings, 2): ");
FXCollections.rotate(strings, 2);
System.out.println("Calling shuffle(strings): ");
FXCollections.shuffle(strings);
System.out.println("Calling shuffle(strings, new Random(0L)): ");
FXCollections.shuffle(strings, new Random(0L));
System.out.println("Calling sort(strings): ");
FXCollections.sort(strings);
System.out.println("Calling sort(strings, c) with custom comparator: ");
FXCollections.sort(strings, new Comparator<String>() {
@Override
public int compare(String lhs, String rhs) {
// Reverse the order
return rhs.compareTo(lhs);
}
});
Search WWH ::




Custom Search