簡體   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