sort() – sort array

Sorts the specified array into ascending numerical order.

Code Explanation
LineDescription
5Declaration and initialization of the array myArray with the values 6, 4, 9, 1, 3, 7
7The sort() Method sorts the array in ascending order
9 – 11With a for loop, each array element is output by specifying the index.
import java.util.Arrays;

public class ArrayMethods {
    public static void main(String[] args) {
        int[] myArray = { 6, 4, 9, 1, 3, 7 };

        Arrays.sort(myArray);

        for (int i = 0; i < myArray.length; i++) {
            System.out.print(myArray[i] + " ");
        }
    }
}
Output
1 3 4 6 7 9