[英]Add an element in arraylist of arraylist using index
I have a arrayList done this way: 我有一个arrayList这样完成:
ArrayList<ArrayList<Double>> level = new ArrayList<ArrayList<Double>>(levels + 1);
So something like: enter image description here 类似于: 在此处输入图片描述
What I would do is add a new element to the internal list saved in a certain index i
of the external list. 我要做的是将一个新元素添加到内部列表中,该元素保存在外部列表的某个索引
i
中。 How can I do this? 我怎样才能做到这一点?
I can't use method arrayList.add(i, 0.0);
我不能使用方法
arrayList.add(i, 0.0);
. 。
Use index from the external ArrayList
and use it to add the number. 使用来自外部
ArrayList
索引,并使用它添加数字。 Like this 像这样
level.get(i).add(1.1);
You need to get the list at a given position first and then insert into it the value desired. 您需要首先在给定位置获取列表,然后将所需的值插入其中。
final List<List<Double>> listOnList = new ArrayList<List<Double>>();
listOnList.add(new ArrayList<Double>());
listOnList.get(0).add(155.0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.