I'm trying to get all the items in a table view and place them in an array list for further processing. This is what I'm trying to achieve but obviously it won't work.
ArrayList<Consultation> showing = consultationTable.getItems();
Nice and recommended solution:
List<Consultation> showing = provider.getItems();
Solution to use only if necessary:
List<Consultation> consultations = provider.getItems();
ArrayList<Consultation> showing;
if (consultations instanceof ArrayList<?>) {
showing = (ArrayList<Consultation>) consultations;
} else {
showing = new ArrayList<>(consultations);
}
If for some reason you need to use an ArrayList method that is not in the List or ObservableList interface (I cannot readily think of why), you may use the latter.
A simple method using Stream class
List<T> list = ObservableList<T>.stream().collect(Collectors.toList());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With