how should i insert a double into a specific part of ArrayList? for example we have a ArrayList with ten doubles each one with the 0 value we want to make the sixth place 10, how should we do that?
Use ArrayList.set()
method:
public E set(int index, E element) Replaces the element at the specified position in this list with the specified element.
For example:
list.set(5, new Double(10));
Just used the indexed add
.
list.add(6, 10D);
EDIT:
But if you want to replace the value at the specified index (instead of inserting a new one), I suggesst you follow @hmjd's solution.
See the documentation: http://docs.oracle.com/javase/1.4.2/docs/api/java/util/ArrayList.html
void add(int index, Object element);
Inserts the specified element at the specified position in this list.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.