我有一个浮点数组和一个字符串数组。每个浮点值都与特定的字符串匹配。我想使用以下方法对保持自己的字符串的浮点数组进行排序:
public static <T> void sort(T[] a,Comparator<? super T> c)
这是代码:
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*/
}
如何按排名和保留自己的字符串进行排序?
非常感谢。