lellus
Technical User
- Apr 25, 2009
- 2
Hi. I don't understand this strange behaviour.
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
int[] number = null;
ArrayList<int[]> numbers = null;
number = new int[1];
numbers = new ArrayList<int[]>();
for ( int value = 0; value<10 ; value++){
number[0] = value;
System.out.println(number[0]);
numbers.add(number);
}
//Output 0 1 2 3 4 5 6 7 8 9
for (int index = 0; index<numbers.size(); index++){
System.out.println(numbers.get(index)[0]);
}
//Output 9 9 9 9 9 9 9 9 9 9
}
Why the second output is different, why i have no store the sequence of numbers into Arraylist as vectors of integers?
Thanks