Java Comparator class to sort particular object array

前端 未结 4 1583
日久生厌
日久生厌 2021-01-16 14:58

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 :



        
4条回答
  •  星月不相逢
    2021-01-16 15:43

    ResultVoiceObject[] objects = ...
    Arrays.sort(objects, new Comparator() {
    
        @Override
        public int compare(ResultVoiceObject arg0, ResultVoiceObject arg1) {
            return Float.compare(arg0.getRanking(), arg1.getRanking());
        }
    
    });
    

提交回复
热议问题