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(short[] 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 shorts.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating an unsorted short array short Arr[] = {10, 2, -3, 35, 56}; //printing unsorted array System.out.print("Before sorting, Arr contains:"); for(short i: Arr) System.out.print(" " + i); //sort the array Arrays.parallelSort(Arr); //printing array after sorting System.out.print("\nAfter sorting, Arr contains:"); for(short i: Arr) System.out.print(" " + i); } }
The output of the above code will be:
Before sorting, Arr contains: 10 2 -3 35 56 After sorting, Arr contains: -3 2 10 35 56
❮ Java.util - Arrays