lambda - Sort a list based on condition in Java 8 -
this question has answer here:
- sort arraylist of custom objects property 23 answers
this not duplicate of question linked. mean have open new question?
i have task class
class task { string personid; string taskid; int sum; }
i have list of tasks - list
1 task50 9 1 task100 12 2 task50 10 3 task1 50
how do this?
sort list such taskid = task50, order sum desc
result list
2 task50 10 1 task50 9 1 task100 12 3 task1 50
to add bit of clarity, result list should contain task50's @ top of list sorted sum in descending order. rest of list should appear in original list.
try this
tasklist.sort((c1, c2) -> c1.gettaskid().equals("task50")&&c2.gettaskid().equals("task50")?c1.getsum().compareto(c2.getsum()):null);
Comments
Post a Comment