I’m putting 1D Arrays in an Array List
ArrayList<int[]> pairs_ref = new ArrayList();
int[]singlePair_ref = new int [2];
singlePair_ref[0] = 15;
singlePair_ref[1] = 0;
pairs_ref.add(singlePair_ref);
return pairs_ref;
However, an test output on the console only shows Zeros, not the correct values
pairs_ref = object_ref.methodFillsArrayListAsShownAbove();
for (int t = 0;t<pairs_ref.size();t++){
int[]array_ref = pairs_ref.get(t);
System.out.println("Live: "+array_ref[0]+" "+array_ref[1]);
}//endfor
this Version brings the same result
int[]array_ref = new int[2];
for (int t = 0;t<pairs_ref.size();
array_ref = pairs_ref.get(t);
System.out.println("Live: "+array_ref[0]+" "+array_ref[1]);
System.out.println(pairs_ref.get(t));}
Why is this? Is it the putting or the getting of the variables of the ArrayList?
Thanks in Advance!
Daniel
Note that as of Java 5 your code can be simplified:
This should work at your system.