You need to sign in to do that
Don't have an account?
SFDC_Evolve
.add function of List .. change the order
lst = usr.Product_Id_s__c.split(',');
system.debug('Print the value of lst'+lst); // In this I got the Order B D A C
for(String s : lst){
system.debug('Print the value of S' + s);
flst.add(s);
}
system.debug('Print the value of the flst'+flst); // the Order got changed in the final Lst . . .
Please help me in this . I have to retain the order in the list . . .
Sorry actually the issue with the Set . i am adding the value in the set from the list then i got sorted !!
All Answers
Even though the value in the S are coming in the right order... .
Sorry actually the issue with the Set . i am adding the value in the set from the list then i got sorted !!
Create a temporary list tempList.
When you add objects to a set do something like this:
if(!mySet.contains(anObject)){
mySet.add(anObject);
tempList.add(anObject); // it will only be added if it hasn't yet been in a set
}
After the loop finishes, tempList will have filtered objects in a correct order (assuming a for loop was iterating in a correct order.
Hope this helps.