Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* package whatever; // don't place package name! */
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- /* Name of the class has to be "Main" only if the class is public. */
- class Ideone {
- public static void main (String[] args) throws java.lang.Exception {
- Integer a[] = {-8, 7, 0, 0, 6, 4, 17, -37, -178, -1, 0, 77 };
- Arrays.sort(a, (x, y) -> x==0 ? y==0 ? 0 : -1 : x<0 ? y<0 ? 0 : y==0 ? 1 : -1 : y>0 ? 0 : 1);
- System.out.println(Arrays.toString(a));
- }
- }
- int a[] = {-8, 7, 0, 0, 6, 4, 17, -37, -178, -1, 0, 77};
- a = IntStream.of(a).boxed().sorted(
- (x, y) -> x == 0 ? Integer.compare(x, Math.abs(y)) :
- y == 0 ? Integer.compare(Math.abs(x), y) :
- Integer.compare(x, y)
- ).mapToInt(Integer::intValue).toArray();
- a = IntStream.of(a).boxed()
- .sorted(Comparator.comparing(i -> i == 0 ? -1 : i > 0 ? 1 : 0))
- .mapToInt(Integer::intValue).toArray();
Add Comment
Please, Sign In to add comment