array .sort java code example
Example 1: sort array java
import java. util. Arrays;
Arrays. sort(array);
Example 2: java sort method
Arrays.sort();//this method is an inbuild function in java
//to sort the array
Example 3: 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]