-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamEx4.java
More file actions
48 lines (30 loc) · 1.11 KB
/
StreamEx4.java
File metadata and controls
48 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.java8.streams;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.SynchronousQueue;
// program to show working of parallel sort
public class StreamEx4 {
public static void main(String[] args) {
String [] str = {"this", "is", "for", "testing", "when", "this", "has", "a", "sample"};
Comparator<String> comparator = new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.compareTo(o2);
}
};
Arrays.parallelSort(str, comparator);
List<String> list = Arrays.asList(str);
list.forEach(System.out::println);
System.out.println("----------------------------------------");
// in java 8 way
Arrays.parallelSort(str, (x,y ) -> y.compareTo(x));
list = Arrays.asList(str);
list.forEach(System.out::println);
System.out.println("************************************");
// with the limits
Arrays.parallelSort(str, 0, 4, comparator);
list = Arrays.asList(str);
list.forEach(System.out::println);
}
}