I have something like the below:
ArrayList<Integer>[] aL = new ArrayList[25];
for (int i = 0; i < aL.length; i++) {
aL[i] = new ArrayList<Integer>();
}
After some logic, I come upon a structure like below:
aL[0] = {492,19,183,193};
aL[1] = {13};
aL[2] = {19,56};
aL[3] = {};
aL[4] = {1};
...
I want to concatenate aL
into a new continuous array. The end result for the above example would be newArray = {492,19,183,193,13,19,56,1,...}
. To note is that I know exactly how many integers there should be in total. I've attempted the below:
newArray = new int[100]; //recall the number of ints is defined, ex. 100
int a = 0;
for (int i = 0; i < aL.length; i++) {
for (int k = 0; k < aL[i].size(); k++) {
newArray[a] = aL[i].remove(0);
a++;
}
}
Upon printing the array, some values are missing. I'm checking how many times the nested loop iterates, and sometimes when aL[i].size()
is 5
for example, it might only iterate 4
times.
newArray[a] = aL[i].get(k);
aL[i].size()
changes as elements are removed and is reflected in the loop conditions.newArray[a] = aL[i].get(k);
instead of0
.