首页 > 解决方案 > 语法问题。如何以与我在评论底部填充双精度数组的方式相同的方式填充双精度列表

问题描述

如何填充双列表与我在评论底部填充双数组的方式相同。

byte b;
short s;
int i;
long l;

private List<List<Product>> products = new ArrayList<>();
private Product[][] productsArray = new products[4][5];

public Automat(){
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 5; j++) {
            products.get(0).get(j) = new Product(b);
        }
    }
}

如下图所示,products.get(0).get(j)被标记为语法错误:

在此处输入图像描述

标签: javaarrayslistcollections

解决方案


您不能将值分配给=ArrayList 的索引位置。您必须使用arrayListObject.set(index, object)

例子:

products.get(0).set(j, new Product(b));

希望这可以帮助。祝你好运。


推荐阅读