【发布时间】:2020-04-15 15:52:37
【问题描述】:
我正在尝试添加以下两个存储在 tempEdges 中的内容:
- [RoyalElephant,IS-A,大象]
- [皇家大象,IS-NOT-A,灰色]
虽然我只希望将每个数组列表的最后 2 个元素添加到复制路径中的 2 个数组列表中。
数组列表是:
public static List<ArrayList<String>> copiedPaths = new ArrayList<>();
public static List<ArrayList<String>> tempEdges = new ArrayList<>();
功能失调的代码是:
copiedPaths.get(0).add(tempEdges.get(0).get(1));
copiedPaths.get(0).add(tempEdges.get(0).get(2));
copiedPaths.get(1).add(tempEdges.get(1).get(1));
copiedPaths.get(1).add(tempEdges.get(1).get(2));
这没有按预期工作,因为两个数组都添加了 IS-NOT-A,灰色而不是一个具有 IS-A,大象和另一个具有IS-NOT-A,灰色
【问题讨论】:
-
我知道,这不是问题
标签: java list arraylist nested add