function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC_EvolveSFDC_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 . . . 

Best Answer chosen by Admin (Salesforce Developers) 
SFDC_EvolveSFDC_Evolve

Sorry actually the issue with the Set . i am adding the value in the set from the list then i got sorted !!

All Answers

SFDC_EvolveSFDC_Evolve

Even though the value in the S are coming in the right order... . 

 

 

SFDC_EvolveSFDC_Evolve

Sorry actually the issue with the Set . i am adding the value in the set from the list then i got sorted !!

This was selected as the best answer
lzanottilzanotti

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.