Was going through Java 8 features, mentioned here. Couldn't understand what parallelSort()
does exactly. Can someone explain what is the actual difference between sort()
and parallelSort()
?
Asked
Active
Viewed 131 times
2

Milad Bahmanabadi
- 946
- 11
- 27

rejoy kulangara
- 71
- 1
- 2
1 Answers
4
Welcome to StackOverflow!
Referring to this article, the difference is that sort
only make use of a single thread to sort the array. On the other hand, parallelSort
make use of multiple thread if the array size if big enough, or use a type of quick sort (dual pivot) if it's a small array.
The main differences stated in that article are:
1) Arrays.sort() : is a sequential sorting.
- The API uses single thread for the operation.
- It takes bit longer time to perform the operation.
2) Arrays.ParallelSort() : is a parallel sorting.
- The API uses multiple threads for the operation.
- It’s faster when there are a lot of elements whereas slower for lesser elements.

Andreas
- 2,455
- 10
- 21
- 24
-
In what scenario we can use the parallelSort? Any one please explain the scenarios in which we should use the both type of sorts – rejoy kulangara Nov 03 '18 at 12:19