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
Post a Comment