I created runnable class in that I created list of type string and added elements on that. How to sort the elements in a list.
Hi Harivenkata,
You can use a Set easily which sort themselves:
dynamicsaxforu.blogspot.com/.../list-set-and-map-in-dynamics-ax-2012.html
Hi Harivenkata
As mentioned by our senior group member, you should sort the record before insert.
Sharing one code sample with you, try with this.
public List arrayFromList(List _list) { System.Collections.ArrayList objTempList=new System.Collections.ArrayList(); ListIterator listIterator; int i; listIterator = new ListIterator(_list); for (i = 1; listIterator.more(); i) { objTempList.Add(listIterator.value()); listIterator.next(); } objTempList.Sort(); _list.empty(); for (i = 0; i< objTempList.Count ; i ) { _list.addEnd(objTempList.Item.ToString()); } return _list; }
Lists contain elements in the order in which you put them. If you want a sorted list, can't you sort the elements before putting them to the list?
Or use a different way for storing the values. My recommendation is an InMemory temporary table - then you can easily use 'order by' when querying the data.
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Andrés Arias as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Sohaib Cheema 745 User Group Leader
Martin Dráb 597 Most Valuable Professional
André Arnaud de Cal... 580 Super User 2025 Season 2