I am currently trying to sort two separate arrays by value then by alphabetical name. How can I do that?
String[] players = new String[5];
int[]goalsByPlayer = new int[5];
players = {a, b, c, d, e};
goalsByPlayer = {3, 0, 0, 0, 0};
1. a 3 goals
2. b 0 goals
3. c 0 goals
4. d 0 goals
5. e 0 goals
If I changed the amount of goals c has to 4, then the list would expected to be...
1. c 4 goals
2. a 3 goals
3. b 0 goals
4. d 0 goals
5. e 0 goals
Please send suggestions!
EDIT: Here is the code I've written.
for (int w = 0; w < number; w++) {
goalsByPlayer[w] *= -1;
}
Arrays.sort(sort);
for (int w = 0; w < number; w++) {
goalsByPlayer[w] *= -1;
}
for (int p = 0; p < number; p++) {
System.out.println((p + 1) + ". " + players[p] + " " + goalsByPlayer[p] + " goals");
}
I am just unaware on how to have the strings match their integers in the array.
Actual output:
1. a 4 goals
2. b 3 goals
3. c 0 goals
4. d 0 goals
5. e 0 goals