473,320 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Sorting Arraylist

I need to sort an ArrayList of objects. I am unable to find a method
for this. DO I need to role my own sorting? Or is there something like
the qsort() function in C of old???

Thanks
Nov 16 '05 #1
6 8171
Hi,
You can use Sort () method. (ArrayList arr = new ArrayList (); arr.Sort
(); )

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
"Bryon" <bl***@whittmanhart.com> je napisal v sporocilo
news:ep**************@TK2MSFTNGP14.phx.gbl ...
I need to sort an ArrayList of objects. I am unable to find a method for
this. DO I need to role my own sorting? Or is there something like the
qsort() function in C of old???

Thanks

Nov 16 '05 #2
Bryon <bl***@whittmanhart.com> wrote:
I need to sort an ArrayList of objects. I am unable to find a method
for this. DO I need to role my own sorting? Or is there something like
the qsort() function in C of old???


Depending on how you want to sort the ArrayList you can use the Sort()
method of the ArrayList class, if you want to sort by something other
than the 'value' of the Objects you may need to implement an IComparer
that does the comparisons on the appropriate values derived from the
objects - see my post about sorting files by creation date earlier.

/J\
Nov 16 '05 #3
Bryon,

Why not use a sortedlist than instead of the arraylist?

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps?

Cor
Nov 16 '05 #4
Cor Ligthert <no************@planet.nl> wrote:
Why not use a sortedlist than instead of the arraylist?

http://msdn.microsoft.com/library/de...ary/en-us/cpre
f/html/frlrfsystemcollectionssortedlistclasstopic.asp

I hope this helps?


If the OP really wants a "normal" list, SortedList is a bad choice -
it's really a map, which also keeps the keys sorted. It's very badly
named, unfortunately.

Fortunately, the Sort method on ArrayList is just what the OP wants, I
believe :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
>
Fortunately, the Sort method on ArrayList is just what the OP wants, I
believe :)


You can be right, however the OP is writing an Arraylist of objects.

I do not know if those objects contain a single value. I don't think so
because he said he was not able to find a method. When you search on MSDN
with "arraylist sort" you get direct the arraylist sort method.

So I think there should me something more.

However I can be wrong in this.

Cor

Nov 16 '05 #6
Cor Ligthert <no************@planet.nl> wrote:
Fortunately, the Sort method on ArrayList is just what the OP wants, I
believe :)
You can be right, however the OP is writing an Arraylist of objects.

I do not know if those objects contain a single value.


Why would it matter?
I don't think so
because he said he was not able to find a method. When you search on MSDN
with "arraylist sort" you get direct the arraylist sort method.


It's sometimes easy to miss the obvious...

<snip>

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: awiklund | last post by:
Hi, I am sorting an arrayList using a custom comparer, but it sort the element in a uncommon fashion. Take a look at this code. using System; namespace ConsoleApplication8
2
by: Rob G | last post by:
Hello, I have a basic understanding of Objects, inheritance, polymorhpism, etc. I am new to VB.NET and I am having a problem figuring this out. I want to sort a CheckBoxList. Using the...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
16
by: RCS | last post by:
So I have an ArrayList that gets populated with objects like: myAL.Add(new CustomObject(parm1,parm2)); I'm consuming this ArrayList from an ObjectDataSource and would like to have this support...
2
by: Rob Meade | last post by:
Dear all, I have a class which contains an arraylist populated with other objects, for example: PrescriptionQueue - containing multiple instances of Prescription I have the need on my web...
16
by: Kittyhawk | last post by:
I would like to sort an Arraylist of objects on multiple properties. For instance, I have a Sort Index property and an ID property (both integers). So, the results of my sort would look like this:...
3
by: djp | last post by:
Hi I have to sort arraylist. I tried to do this using this page as a reference: http://www.java2s.com/Code/CSharp/Collections-Data-Structure/UseIComparer.htm I did it exactly the same way but...
12
by: Justin | last post by:
Ok, I give up. I can't seem to construct a decent (productive) way of sorting my arraylist. I have a structure of two elements: Structure TabStructure Dim TabName As String Dim FullFilePath...
4
by: slapsh0t11 | last post by:
Hello! I need help with a program that I believe I am nearly done with. However, there seems to be a few details that preclude me from success. Here is my assignment: Here is my class file...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.