We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi
I have 2 arrays, one int, one string and I want to be able to sort them in exactly the same way
String[] animal = {"dog","cat","duck,","pig","cow"};
int[] score = {5,9,3,8,2};
I then proceed to sort score like this:
score = sort(score);
score = reverse(score);
so score is now like {9,8,5,3,2}
I now want to sort animal the exact same way as if cat is bound to 9 and dog is bound to 5. How can I do this?
Answers
If I were you, I would create a class called
AnimalScore
that contained both theString
andint
value. Then you'd just have a single array that held instances of that class, and you could sort that by the score.Thank you very much, that helps so much!