Solved

Sorting an object based on 2 values

Posted on 2006-11-02
5
222 Views
Last Modified: 2010-03-31
Hello, I have an array of objects with 2 fields: String Key, and int dID.


What I want to do is sort the array first by the Key, and then by the dID.

for example:

"Hello", 7
"Hello", 4
"Apple", 9

Becomes:  "Apple", 9
                "Hello", 4
                "Hello", 7

Before I start sorting, the array is already sorted by dID, so I am wondering if there is a sorting algorithm that will sort the Keys, while keeping the dID's in order like my example above.

If there is no such algorithm, what is the best method to go about achieving this?

Thanks  

0
Comment
Question by:twibblejaway
  • 3
  • 2
5 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 17863529
0
 

Author Comment

by:twibblejaway
ID: 17863772
ok, so i have that working, and I can print out the list to verify that it is sorted appropriatly.  How can I get my original object array back now though?  I dont even need to get it back as an array, is there just a way I can remove the object one at a time?  
0
 
LVL 92

Expert Comment

by:objects
ID: 17863788
if you need the original array then take a copy before sorting (or resort it depending on your exact needs)
0
 

Author Comment

by:twibblejaway
ID: 17863790
I dont need the original.  What I need is to be able to take 1 element out of the newly sorted array at a time.  
0
 
LVL 92

Expert Comment

by:objects
ID: 17863813
better off using a List if you want to be removing elements.
With an array best you can do is set the element to null.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

821 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