web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

sorting string list

(0) ShareShare
ReportReport
Posted on by 60

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.

I have the same question (0)
  • Verified answer
    huijij Profile Picture
    19,811 on at
    RE: sorting string list

    Hi Harivenkata,

    You can use a Set easily which sort themselves:

    dynamicsaxforu.blogspot.com/.../list-set-and-map-in-dynamics-ax-2012.html

  • Verified answer
    Sheikh Sohail Profile Picture
    6,125 on at
    RE: sorting string list

    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;
        }

  • Martin Dráb Profile Picture
    235,876 Most Valuable Professional on at
    RE: sorting string 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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 745 User Group Leader

#2
Martin Dráb Profile Picture

Martin Dráb 597 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 580 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans