Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sort Arraylist of String[]

Posted on 2007-11-28
5
Medium Priority
?
993 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 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