You need to sign in to do that
Don't have an account?

Values are not displaying in proper list indices!!
Hey all,
I am stuck in my code where i need help in lists
I have my code something like this.
List<String[]> rowAlter= new List<String[]>(size);
Integer i=1,j=2;
for(String[] r : csv1) {
system.debug('odd-->'+r+'!!!!!---'+i);
rowAlter.add(i,r);
system.debug('odd rowalter--'+i+'--'+rowAlter[i]);
i=i+2;
}
system.debug('before rowAlter[3]= '+rowAlter[3]);
for(String[] s : csv2) {
system.debug('even-->'+s+'!!!!!---'+j);
rowAlter.add(j,s);
system.debug('even rowalter--'+j+'--'+rowAlter[j]);
j=j+2;
}
when i check debug logs for (system.debug('odd rowalter--'+i+'--'+rowAlter[i]);)
all the values are correctly placed in odd indices.
but again when the control comes in the for loop for even indices,all the values are correctly placed for even indices but odd indices values are not in order and few of them are null.I tried a lot to replicate the issue but couldn't.I really need a help in this.Please can anyone help me resolve it?
I am stuck in my code where i need help in lists
I have my code something like this.
List<String[]> rowAlter= new List<String[]>(size);
Integer i=1,j=2;
for(String[] r : csv1) {
system.debug('odd-->'+r+'!!!!!---'+i);
rowAlter.add(i,r);
system.debug('odd rowalter--'+i+'--'+rowAlter[i]);
i=i+2;
}
system.debug('before rowAlter[3]= '+rowAlter[3]);
for(String[] s : csv2) {
system.debug('even-->'+s+'!!!!!---'+j);
rowAlter.add(j,s);
system.debug('even rowalter--'+j+'--'+rowAlter[j]);
j=j+2;
}
when i check debug logs for (system.debug('odd rowalter--'+i+'--'+rowAlter[i]);)
all the values are correctly placed in odd indices.
but again when the control comes in the for loop for even indices,all the values are correctly placed for even indices but odd indices values are not in order and few of them are null.I tried a lot to replicate the issue but couldn't.I really need a help in this.Please can anyone help me resolve it?
You need to do something like this :
Adjust the values of 'i' & 'j' and size(here i have harcoded size as 10) as per your requirement.
Please mark this question as Solved if this helps you so that others can view it as a proper solution.
Thanks,
Apoorv