java - How can I subtract from arraylist some values ? -
here example:
public static arraylist<integer> position = new arraylist<integer>(); public static arraylist<integer> new_position = new arraylist<integer>(); collections.copy(new_position, position); (int j = 0; j < position.size(); j++) { new_position.get(j) -=4; }
i want copy values , new arraylist subtract 4. how can make ? i'm new in java. i've got error such as: the left-hand side of assignment must variable
, refers nowe_pozycje.get(j) -=4;
.
you have get()
value, change it, , set()
new value:
for (int j = 0; j < position.size(); j++) { new_position.set(j, new_position.get(j) - 4); }
an alternative solution skip whole copying of list, , instead iterate through original list, change each value go, , add them new list
:
public static arraylist<integer> new_position = new arraylist<integer>(); (integer i: position) { new_position.add(i - 4); }
Comments
Post a Comment