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 :
public static <T> void sort(T[] a,Comparator<? super T> c)
Here is the code:
public class ResultVoiceObject
{
private String frase;
private float ranking;
public ResultVoiceObject(String f, float r)
{
this.frase=f;
this.ranking= r;
}
}
public class VoiceRecognitionDemo extends Activity
{
// Populate the wordsList with the String values the recognition engine thought it heard
ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
//il Ranking
float[] score= data.getFloatArrayExtra(RecognizerIntent.EXTRA_CONFIDENCE_SCORES);
ResultVoiceObject[] risultati= new ResultVoiceObject[score.length];
for (i=0; i<risultati.length;i++)
{
risultati[i]=new ResultVoiceObject(matches.get(i), score[i]);
}
ResultVoiceObject[] risultatiDaOrdinare= risultati; // risultati contais ResultVoiceObject elements
/*sorting*/
}
How can I sort by ranking and keeping the own String?
Thanks a lot.