【问题标题】:SyntaxProblem. How to fill double List the same way how I filled the double array at the bottom in comments语法问题。如何填充双列表与我在评论底部填充双数组的方式相同
【发布时间】:2020-01-02 11:13:12
【问题描述】:

如何填充双精度列表,方法与我在 cmets 中填充底部双精度数组的方式相同。

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) 被标记为语法错误:

【问题讨论】:

  • 请添加代码而不是截图!
  • 你应该在这里添加代码然后我们可以测试它并给出答案
  • @HarshalParekh - 两个原因。首先,许多人的网站会阻止附件,而许多其他可能会有所帮助的人拒绝下载附件,原因与其他人阻止附件的原因相同。其次,屏幕截图使他人无法复制代码并在自己的系统中进行测试。
  • @EdStevens,我知道,我要让 OP 知道同样的情况。如果你去链接,你会明白的。

标签: java arrays list collections


【解决方案1】:

您不能使用 = 为 ArrayList 的索引位置赋值。你必须使用arrayListObject.set(index, object)

例子:

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

希望这会有所帮助。祝你好运。

【讨论】:

    猜你喜欢
    • 2020-09-01
    • 2023-04-02
    • 1970-01-01
    • 2019-08-08
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    • 2017-10-01
    • 1970-01-01
    相关资源
    最近更新 更多