本文介绍了如何将可观察列表转换为数组列表?爪哇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在表格视图中获取所有项目,并将它们放置在数组列表中以进行进一步处理.这是我要实现的目标,但是显然行不通.

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();

推荐答案

很好的建议解决方案:

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);
    }

如果由于某种原因需要使用不在List或ObservableList接口中的ArrayList方法(我不容易想到为什么),则可以使用后者.

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.

这篇关于如何将可观察列表转换为数组列表?爪哇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 16:52