J
Jeremy Watts
I have created a List with the intention of putting elements of
one-dimensional arrays within it. The arrays contain integers. The lines
I've used are:-
(for the purposes of this, I have set variableNumber equal to 5)
List<int[]>combinationList = new ArrayList<int[]>();
int[] degrees = new int[variableNumber + 1];
{ some routine which fills each element of 'degrees' with a random integer}
then, I wish to add the newly filled 'degrees' to the end of the list, using
:-
combinationList.add(degrees);
theres no problem just doing this the once, but if I attempt to add another
instance of 'degrees' to the list using the same above statement, then it
seems to overwrite the initial instance of degrees with the new one.
Why is it doing this? I cant seem to find a way around it. If I run
through say 10 iterations of the above then I am simply left with a list of
10 arrays all of which are identical to the last generated instance of
'degrees'.
Thanks
one-dimensional arrays within it. The arrays contain integers. The lines
I've used are:-
(for the purposes of this, I have set variableNumber equal to 5)
List<int[]>combinationList = new ArrayList<int[]>();
int[] degrees = new int[variableNumber + 1];
{ some routine which fills each element of 'degrees' with a random integer}
then, I wish to add the newly filled 'degrees' to the end of the list, using
:-
combinationList.add(degrees);
theres no problem just doing this the once, but if I attempt to add another
instance of 'degrees' to the list using the same above statement, then it
seems to overwrite the initial instance of degrees with the new one.
Why is it doing this? I cant seem to find a way around it. If I run
through say 10 iterations of the above then I am simply left with a list of
10 arrays all of which are identical to the last generated instance of
'degrees'.
Thanks