I have two arrays that are not sorted: a float array (float[]
), and a String array (String[]
) for the descriptions.
I need to sort the float array from the highest value to the lowest, but the descriptions are in the String array and if I sort them, the String array won't be sorted accordingly.
In Processing, there is a sort(Array)
function, but it only sorts one array.
How can I sort the float array and have the descriptions match?
float totalCount = 0;
float maxValue = 0;
String[] statusDescriptions = new String[finishStatusesJSON.size()];
float[] countData = new float[finishStatusesJSON.size()];
for (int i = 0; i < finishStatusesJSON.size(); i++) {
JSONObject finishStatusJSON = (JSONObject) finishStatusesJSON.get(i);
float count = finishStatusJSON.getFloat("count");
String status = finishStatusJSON.getString("status");
totalCount += count;
statusDescriptions[i] = status;
countData[i] = count;
// Max value of the table
if(maxValue < count) maxValue = count;
}