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(double[] 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 doubles.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating an unsorted double array
    double Arr[] = {10d, 2d, -3d, 35d, 56d};

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

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

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

The output of the above code will be:

Before sorting, Arr contains: 10.0 2.0 -3.0 35.0 56.0
After sorting, Arr contains: -3.0 2.0 10.0 35.0 56.0

❮ Java.util - Arrays