arrays.sort numbvers java code example
Example 1: 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]
Example 2: java array sortieren
int[] intArray = {1, 5, 3, 7, 2, 9};
Arrays.sort(intArray);
System.out.println(Arrays.toString(intArray));
// Ausgabe: [1, 2, 3, 5, 7, 9]