• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

Sorting an object based on 2 values

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
twibblejaway
Asked:
twibblejaway
  • 3
  • 2
1 Solution
 
objectsCommented:
0
 
twibblejawayAuthor Commented:
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
 
objectsCommented:
if you need the original array then take a copy before sorting (or resort it depending on your exact needs)
0
 
twibblejawayAuthor Commented:
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
 
objectsCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now