How to sort an array in Java?

To sort an array in Java, use Arrays.sort.

Here's how you do it:

int[] array = new int[] { 1, 74, 5, -5 };

java.util.Arrays.sort(array);

// [-5, 1, 5, 74]
System.out.println(java.util.Arrays.toString(array));