Arrays.sort(char[]) in Java

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

Syntax:

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

This method takes one argument of type char 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 Arrayssortchar {
    public static void main(String[] args) {

        char a[] = { 'd', 'a', 'f', 'e', 'o', 'z', 'c' };

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

Output:

[a, c, d, e, f, o, z]


No comments:

Post a Comment