繁体   English   中英

数组列表 <Double> 插入(Java)的

[英]ArrayList<Double> insertion(java)

我应该如何将双重插入ArrayList的特定部分? 例如,我们有一个ArrayList,其中每个都有10个双精度值,我们希望将其设为第6位10,我们应该怎么做?

使用ArrayList.set()方法:

public E set(int index,
             E element)

Replaces the element at the specified position in this list
with the specified element.

例如:

list.set(5, new Double(10));

刚刚使用了索引add

list.add(6, 10D);

编辑:

但是如果你想替换指定索引处的值(而不是插入一个新值),我建议你按照@hmjd的解决方案。

请参阅文档: http//docs.oracle.com/javase/1.4.2/docs/api/java/util/ArrayList.html

void add(int index, Object element);

将指定元素插入此列表中的指定位置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM