Solved

Sort arraylist

Posted on 2015-01-30
5
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

717 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