Arrays.sort(short[]) in Java

Arrays.sort(short[]): This method is available in java.util.Arrays class of Java.

Syntax:

void java.util.Arrays.sort(short[] a)

This method takes one argument of type short array as its parameter. This method sorts the specified array into ascending numerical order.

Parameters: One parameter is required for this method.

a: the array to be sorted.

Returns: NA

Exceptions: NA

Approach

Java

import java.util.Arrays;

public class Arrayssortshort {
    public static void main(String[] args) {

        short a[] = { 12, 6, 6, 2, 4, 56, 23 };

        Arrays.sort(a);
        System.out.println(Arrays.toString(a));
    }
}

Output:

[2, 4, 6, 6, 12, 23, 56]


No comments:

Post a Comment