I have a 2D ArrayList and I want to replace one of the elements with something else by using the set
method.
According to the Java API:
set(int index, E Element)
is the constructor. How do I input the index, given that the ArrayList is 2D?
If you have a two-dimensional ArrayList
, then what you need to do is
outerList.get(x).set(y, newValueAtXY);
...which gets the row at index x
and sets element y
in that row to newValueAtXY
.
I came across this while searching:
array.get(i1).put(i2, value);
I think, it can be modified like this:
array.get(i1).set(i2, value);
I hope it works.
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.