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]
Source: stackoverflow.com
sort an int array java
import java.util.Arrays; class GFG { public static void main(String args[]) { int[] arr = { 5, -2, 23, 7, 87, -42, 509 }; System.out.println("The original array is: "); for (int num : arr) { System.out.print(num + " "); } Arrays.sort(arr); System.out.println("\nThe sorted array is: "); for (int num : arr) { System.out.print(num + " "); } } }
Source: www.geeksforgeeks.org