You need to sign in to do that
Don't have an account?
inbox outbox 7
How to reverse a list?
Please correct my code and advice me on what I am doing wrong.
public List<Account> sortingMethod1() { List<Account> accList= new List<Account>(); accList.add(new Account(Name= 'a')); accList.add(new Account(Name= 'z')); accList.add(new Account(Name= 'c')); accList.add(new Account(Name= 'd')); accList.add(new Account(Name= 'p')); accList.add(new Account(Name= 'n')); INSERT accList; List<Account> reversedList= new LIst<Account>(); for(integer I= accList.size()-1; i>=0; i--){ reversedList.add(accList.get(I)); } return reversedList; }
Your code is already returning the list in reverse manner only. or you want to arrange account names in orderly and revised.
Thanks,
Maharajan.C