Answers for "how to arrange array"

0

java sort int array

// an array of ints
int[] arr = {1, 2, 3, 4, 5, 6};

// an array of reverse sorted ints
int[] arrDesc = Arrays.stream(arr).boxed()
    .sorted(Collections.reverseOrder())
    .mapToInt(Integer::intValue)
    .toArray();

System.out.println(Arrays.toString(arrDesc)); // outputs [6, 5, 4, 3, 2, 1]
Posted by: Guest on September-01-2020

Code answers related to "how to arrange array"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language