I have a float array and a String array. each float value match with a specific String. I would like to sort the float array keeping the own string using :
Assuming you have a getRanking()
accessor for the private field ranking
.
public class ResultComparator implements Comparator {
public int compare(ResultVoiceObject r1, ResultVoiceObject r2) {
float f1 = r1.getRanking();
float f2 = r2.getRanking();
if(f1 > f2) return 1;
else if(f1 < f2) return -1;
return 0;
}
}
Arrays.sort(resultsArray, new ResultComparator());