?
Solved

Sort arraylist

Posted on 2015-01-30
5
Medium Priority
?
177 Views
Last Modified: 2016-02-17
I have an arraylist

Untitled.png
I need to sort array by the number before the comma

I need it with lowest to highest
0
Comment
Question by:Jason
  • 2
  • 2
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40579562
I would suggest to split up the values into a small helper class, and compare using the proper parts with the propert data types. which means to sort by "part(6)" from the source data

trying to sort like this after the string concatenation is not really efficient...

hence, can you not sort the "input" instead?
0
 

Author Comment

by:Jason
ID: 40579596
If i separate them how do you keep the association between them
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40579623
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 40580216
Why are you using an ArrayList?...they are deprecated and hard to work with.

It can be done, however:
        Dim list As New ArrayList
        list.Add("10.90,1")
        list.Add("7.50,2")
        list.Add("20.40,3")
        list.Add("4.40,4")
        list.Add("11.70,5")
        list.Add("10.80,6")
        list.Add("48.00,7")
        list.Add("2.50,8")
        list.Add("12.80,9")

        list = New ArrayList(list.ToArray.Select(Function(x) x.ToString).ToList.OrderBy(Function(x) CDbl(x.Split(",")(0))).ToArray)
        For Each x In list
            Debug.Print(x)
        Next

Open in new window


If you can't use the fancy LINQ stuff, then you'll have to go with Guy's suggestion.

Preferably, though, you should be using a List and have those values in some kind of structure (like a Class); then you could sort it quite easily.
0
 

Author Closing Comment

by:Jason
ID: 40580872
Great works awesome
Only using arraylist because it is extracted from another arraylist
will need to look at LINQ.

Thx heaps
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question