Java Comparator class to sort particular object array

前端 未结 4 1578
日久生厌
日久生厌 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:53

    I solved merging both answare:

    public class VoiceRecognitionDemo extends Activity implements Comparator() {
                @Override
                public int compare(ResultVoiceObject arg0, ResultVoiceObject arg1) {
                    return Float.compare(arg0.getRanking(), arg1.getRanking());
                }
            });  
    
        }
    
    
    public int compare(ResultVoiceObject lhs, ResultVoiceObject rhs) {
        // TODO Auto-generated method stub
        return 0;
    }
    

    }

    Where:

     public class ResultVoiceObject
     {
    
     private  String frase;
     private float ranking;
     public ResultVoiceObject(String f, float r) 
       {
        this.frase=f;
        this.ranking= r;
       }  
     }
    

    Another way is:

    ADD

    import java.util.Arrays;

    import java.util.Comparator;

    REMOVE: implements Comparator and the compare methos out onActivityResult

    Thanks stackoverflow comunity!

提交回复
热议问题