473,385 Members | 1,848 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,385 software developers and data experts.

Sort Arraylist Integers

Hi Guys,

Just wondering if someone could help me with an arraylist issue.

I have an array of integers

Arraylist
4 , 2, 11, 2, 21, 3 ,15 , 30

i want the arraylist to now be sorted according to the values either
ascending or descending.

at present it appears that the arraylist.sort() method sorts these
values as text ie. 11,13,2,2,3,30 etc...

can anyone help

thanks

CG

Jul 10 '06 #1
2 2360
Use Sort with a comparer. A comparer for integers is easy to implement. Look
at this MSDN example:

http://msdn2.microsoft.com/en-us/library/0e743hdt.aspx

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"csgraham74" <cs********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hi Guys,

Just wondering if someone could help me with an arraylist issue.

I have an array of integers

Arraylist
4 , 2, 11, 2, 21, 3 ,15 , 30

i want the arraylist to now be sorted according to the values either
ascending or descending.

at present it appears that the arraylist.sort() method sorts these
values as text ie. 11,13,2,2,3,30 etc...

can anyone help

thanks

CG

Jul 10 '06 #2
pad single digits with a leading zero before adding them to the array...
"csgraham74" <cs********@gmail.comwrote in message news:11**********************@b28g2000cwb.googlegr oups.com...
Hi Guys,

Just wondering if someone could help me with an arraylist issue.

I have an array of integers

Arraylist
4 , 2, 11, 2, 21, 3 ,15 , 30

i want the arraylist to now be sorted according to the values either
ascending or descending.

at present it appears that the arraylist.sort() method sorts these
values as text ie. 11,13,2,2,3,30 etc...

can anyone help

thanks

CG

Jul 10 '06 #3

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

Similar topics

7
by: Jerry S | last post by:
Hi I've got an arraylist of integers. I want to be able to remove an integer from the list using a method like this: public void ArrayListRemove(int indexnum) {...
1
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting,...
4
by: Mike Dole | last post by:
I have an arraylist like the one with the Guitar Class sample in Q316302. Dim MycolliCol as arraylist Private Sub FillArray() MyColliCol.Add(New Colli(1, "STUK", 0)) MyColliCol.Add(New...
3
by: Adam J. Schaff | last post by:
Hello. I recently noticed that the Sort method of the .NET ArrayList class does not behave as I expected. I expect 'A' < '_' < 'a' (as per their ascii values) but what I got was the opposite....
4
by: Peter | last post by:
I run into this situation all the time and I'm wondering what is the most efficient way to handle this issue: I'll be pulling data out of a data source and want to load the data into an array so...
19
by: Derek Martin | last post by:
Hi there, I have been playing with sorting my arraylist and having some troubles. Maybe just going about it wrong. My arraylist contains objects and one of the members of the object is 'name.' I...
5
by: Disccooker | last post by:
and i'm lost. any ideas? It's an object with a public property that is an Int. i receive an Array of these objects and copy them to an arraylist. i need to sort it based on this property and i...
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
14
by: budy_ludy | last post by:
Hi All, I am new to vb .net, I have an ArrayList and i store class objects in it, and later i want to retrieve each ArrayList items and type cast to the class, How can it be done ? I used...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.