Solved

Sort Arraylist of String[]

Posted on 2007-11-28
5
983 Views
Last Modified: 2013-12-17
I have an arraylist that contains string [] objects.  The arraylist looks like

arraylist.add(new string [] {name, phone});

How can I sort the arraylist by name?
0
Comment
Question by:Rowdyone52
[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
5 Comments
 
LVL 4

Expert Comment

by:aumudin
ID: 20369234
0
 

Author Comment

by:Rowdyone52
ID: 20369258
That doesnt use arraylists.
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 500 total points
ID: 20369355
Create a class that implements IComparer and use that to sort the ArrayList:
public class PhoneComparer : IComparer  {
   int IComparer.Compare(object x, object y) {
      return string.Compare(((string[])x)[0], ((string[])y)[0]);
   }
}
 
arraylist.Sort(new PhoneComparer());

Open in new window

0
 
LVL 22

Expert Comment

by:JimBrandley
ID: 20369365
It's pretty easy to do if you write your own IComparer. There's an example of how to do that here:

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

Jim
0
 

Author Closing Comment

by:Rowdyone52
ID: 31597123
Excellent!  Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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