Java Utility Library

Java Arrays - parallelSort() Method



The java.util.Arrays.parallelSort() method is used to sort the specified array into ascending numerical order. The sorting algorithm is a parallel sort-merge that breaks the array into sub-arrays that are themselves sorted and then merged. When the sub-array length reaches a minimum granularity, the sub-array is sorted using the appropriate Arrays.sort method. If the length of the specified array is less than the minimum granularity, then it is sorted using the appropriate Arrays.sort method.

Syntax

public static void parallelSort(char[] a)

Parameters

a Specify the array to be sorted.

Return Value

void type.

Exception

NA.

Example:

In the example below, the java.util.Arrays.parallelSort() method is used to sort a specified array of chars.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating an unsorted char array
    char Arr[] = {'u', 'a', 'i', 'e', 'o'};

    //printing unsorted array
    System.out.print("Before sorting, Arr contains:"); 
    for(char c: Arr)
      System.out.print(" " + c);

    //sort the array
    Arrays.parallelSort(Arr);

    //printing array after sorting
    System.out.print("\nAfter sorting, Arr contains:"); 
    for(char c: Arr)
      System.out.print(" " + c);   
  }
}

The output of the above code will be:

Before sorting, Arr contains: u a i e o
After sorting, Arr contains: a e i o u

❮ Java.util - Arrays