2. Apache Commons Collections:
import javafx.collections.ObservableList;
import javafx.collections.FXCollections;
public class Main {
public static void main(String[] args) {
ObservableList<String> names = FXCollections.observableArrayList();
names.add("John");
names.add("Jane");
names.add("Bob");
names.addListener((ListChangeListener<String>) c -> {
while (c.next()) {
if (c.wasAdded()) {
for (String name : c.getAddedSubList()) {
System.out.println("New name added: " + name);
}
}
if (c.wasRemoved()) {
for (String name : c.getRemoved()) {
System.out.println("Name removed: " + name);
}
}
}
});
names.add("Alice");
names.remove("Bob");
}
}