I have below code where I need to modify the List during iteration. It throws error. can someone suggest a way out in this case? **Error **
System.FinalException: Cannot modify a collection while it is being iterated.
Apex Code
for(Survey_Question_vod__c sq: surveyInstanceList )
{
if(sq.text_vod__c!=null)
{
String formattedStr =sq.text_vod__c;
String[] strArr = formattedStr.split(' ');
strNumber = strArr[1];
mynumber=Integer.valueof(strNumber.substring(0,1));
If(mynumber==count)
{
surveyInstanceListsorted.add(sq);
count++;
}
else
{
surveyInstanceList.add(sq);
}
}
}