forked from eh3rrera/ocpj8-book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch18a.html
65 lines (40 loc) · 2.69 KB
/
ch18a.html
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
61
62
63
64
65
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Study guide for the Oracle Certified Professional, Java SE 8 Programmer Exam ">
<title>Java 8 Programmer II Study Guide: Exam 1Z0-809</title>
<link href="css/code.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="js/common-sections.js"></script>
</head>
<body>
<div class="header">
<div class="title-container">
<div class="chapter-title">
<h1><i class="chapter">Chapter EIGHTEEN</i><br />
Parallel Streams</h1>
<p><br /></p>
<h3 style="text-align: center;"><i>Exam Objectives</i></h3>
<p style="text-align: center;"><i>Use parallel Streams including reduction, decomposition, merging processes, pipelines and performance.</i><br /></p>
</div>
</div>
</div>
<div class="container">
<div class="column">
<h2>Answers</h2>
<p><b>1. The correct answer is B.</b><br /> Sums are associative operations, therefore, the <code>reduce()</code> method ensures that the stream can be processed in parallel while preserving the order of its elements.</p>
<p><br /></p>
<p><b>2. The correct answer is C.</b><br /> Option A is false. <code>Collection</code>s use the <code>parallelStream()</code> method.<br /> Option B is false. Operations that are computationally expensive, generally have a better performance using a parallel stream.<br /> Option C is true. <code>filter()</code> is considered stateless.<br /> Option D is false. Parallel streams don't always perform better than sequential streams.</p>
<p><br /></p>
<p><b>3. The correct answer is A.</b><br /> If you remember from the previous chapter, the <code>average()</code>, <code>sum()</code>, <code>max()</code>, and <code>min()</code> methods are implemented as a reduce operation with the <code>collect()</code> method, so the stream can be safely processed in parallel.</p>
<p><br /></p>
<p><b>4. The correct answer is D.</b><br /> The call of <code>sequential()</code> turns the whole stream pipeline into a sequential one. In general, we can say that the last call to <code>parallel()</code> or <code>sequential()</code> is the one that affects the whole stream pipeline.</p>
<p><br /></p>
</div>
</div>
<footer></footer>
</body>
</html>