sorting - Java sort one always on top -


i have following class:

    public class rating{       private int userid;       private int value;     //getters , setters     } 

i want every time userid == 1000 on top , below rating in descending order.

i tried following not seem work:

list.sort((o1, o2) -> {             if(o2.getuserid() == 1000){                 return 1;             }             return integer.compare(o2.getvalue(), o1.getvalue());         }); 

thank you

list.sort((o1, o2) -> {         if (o1.getuserid() == o2.getuserid()) {             return integer.compare(o2.getvalue(), o1.getvalue());         } else if(o1.getuserid() == 1000) {             return -1;         } else if (o2.getuserid() == 1000) {             return 1;         }         return integer.compare(o2.getvalue(), o1.getvalue());     }); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -