下面是一个例子:如何从arraylist中减去一些值?
public static ArrayList<Integer> position = new ArrayList<Integer>();
public static ArrayList<Integer> new_position = new ArrayList<Integer>();
Collections.copy(new_position, position);
for (int j = 0; j < position.size(); j++) {
new_position.get(j) -=4;
}
我要复制值,然后从我的新的ArrayList减4.我怎么能做到吗? 我是新来的java。另外我有一个错误,如:The left-hand side of an assignment must be a variable
,它是指nowe_pozycje.get(j) -=4;
。
获取值,从中减去,然后放回原处。一个'ArrayList'不是一个数组。 –
'subtract 4'的意思是?你到底想做什么?你想删除4个元素吗? – Vishrant