Reputation: 704
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?
Upvotes: 0
Views: 2435
Reputation: 143
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.
Upvotes: 0
Reputation: 198023
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
.
Upvotes: 3