#sorting doesn't want to work
11 messages · Page 1 of 1 (latest)
Hey, @strange veldt!
Please remember to /close this post once your question has been answered!
this one will sort even numbers after odd ones
you could stream's partitionBy.
pass in your partition criteria
then run a foreach on the list it returned sorting them.
then you can collect the result in a list
what was the list before and what was it after?
your code runs as expected on my machine
List<Integer> ints = Arrays.asList(5, 8, 4, 7, 3, 1, 2, 9, 6); Collections.sort(ints, (l1, l2) -> { int a = (int) l1; int b = (int) l2; if (a % 2 == 0 && b % 2 != 0) { return 1; } return -1; });
or
`List<Integer> ints = Arrays.asList(5, 8, 4, 7, 3, 1, 2, 9, 6);
Collections.sort(ints, (l1, l2) -> {
return l1%2==0 && l2%2!=0 ? 1 : -1;
});
System.out.println(ints);`
gives this output
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use/help ping.
Warning: abusing this will result in moderative actions taken against you.