forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
60 lines (42 loc) · 2.11 KB
/
Main.java
File metadata and controls
60 lines (42 loc) · 2.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
49
50
51
52
53
54
55
56
57
58
59
60
package modern.challenge;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Spliterator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public class Main {
public static void main(String[] args) throws IOException {
String str = "Character Information 字 Development and Maintenance "
+ "Project 盤 for e-Government MojiJoho-Kiban 事 Project";
Spliterator<Character> spliterator = new IdeographicSpliterator(str);
Stream<Character> stream = StreamSupport.stream(spliterator, true);
// force spliterator to do its job
stream.collect(Collectors.toList());
System.out.println("\n---------------------------------------------\n");
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
Spliterator<Integer> s1 = numbers.spliterator();
s1.tryAdvance(e -> System.out.println("Advancing to the first element of s1: " + e));
System.out.println("\nEstimated size of s1: " + s1.estimateSize());
Spliterator<Integer> s2 = s1.trySplit();
System.out.println("\nSplitting s1 ...");
System.out.println("Estimated size s1: " + s1.estimateSize());
System.out.println("Estimated size s2: " + s2.estimateSize());
System.out.println("\nPrint remaining elements of s1:");
s1.forEachRemaining(System.out::println);
System.out.println("\nPrint remaining elements of s2:");
s2.forEachRemaining(System.out::println);
System.out.println("\nCharacteristics:");
System.out.println(s1.characteristics());
System.out.println(s2.characteristics());
System.out.println("\nCheck that s1 is ordered:");
if (s1.hasCharacteristics(Spliterator.ORDERED)) {
System.out.println("ORDERED");
}
System.out.println("\nCheck that s1 is sized:");
if (s1.hasCharacteristics(Spliterator.SIZED)) {
System.out.println("SIZED");
}
}
}