首页 > 解决方案 > 将arraylist的第一个元素分配给另一个arraylist

问题描述

如何从另一个类中获取 ArrayList 的第一个元素并将其分配给另一个 ArrayList?

public class PaymentScreenController {

    public ListView<Customer> lvCustomer1;
    public ArrayList<Customer> allcustomers;

    public ArrayList<Customer> cusarray;


    private Table tbl = new Table();

    @FXML
    public void initialize() {

        allcustomers = tbl.getCustomers();

        // Getting first element from 'allcustomers and assigning it to cusarray?
        // I have tried cusarray = allcustomers.get(0) but that doesn't work?









    }
}

然后将 cus 数组分配给列表视图?

任何帮助将不胜感激谢谢

标签: javajavafx

解决方案


尝试:

cusarray.add(allcustomers.get(0));

推荐阅读