lambda - Sort a list based on condition in Java 8 -


this question has answer here:

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

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 -