Reimplement Exercise 17.10 using parallelstreams. Use the Date/Time API timing techniques to compare the time required for
Question:
Reimplement Exercise 17.10 using parallelstreams. Use the Date/Time API timing techniques to compare the time required for the sequential and parallel versions of the program.
Exercise 17.10
Modify the program of Fig. 17.22 to summarize the number of occurrences of every character in the file.
Fig. 17.22
Transcribed Image Text:
1234 3 import java.io.IOException; 4 import java.nio.file.Files; 5 import java.nio.file.Paths; 6 import java.util.Map; 7 import java.util.TreeMap; import 8 9 13 14 15 10 II public class StreamOfLines { 12 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 // Fig. 17.22: StreamOfLines.java // Counting word occurrences in a text file. NNNNNNMMMM MM 33 34 java.util.regex.Pattern; import java.util.stream.Collectors; 35 } public static void main(String[] args) throws IOException { // Regex that matches one or more consecutive whitespace characters Pattern pattern = Pattern.compile("\\s+"); // count occurrences of each word in a Stream sorted by word Map wordCounts = Files.lines (Paths.get("Chapter 2Paragraph.txt")) .flatMap (line -> pattern.splitAsStream (line)) .collect(Collectors.grouping By (String: :toLowerCase, TreeMap::new, Collectors.counting (())); // display the words grouped by starting letter wordCounts.entrySet() .stream() .collect( Collectors.grouping By (entry entry.getKey().charAt(0), TreeMap:: new, Collectors.toList())) .forEach ((letter, wordList) -> { System.out.printf("%n%C%n", letter); wordList.stream().forEach (word > System.out.printf( "%13s: %d%n", word.getKey(), word.getValue(())); });
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 66% (3 reviews)
To reimplement Exercise 1710 using parallel streams we need to modify the stream operations to their parallel counterparts and add timing mechanisms t...View the full answer
Answered By
Muhammad Umair
I have done job as Embedded System Engineer for just four months but after it i have decided to open my own lab and to work on projects that i can launch my own product in market. I work on different softwares like Proteus, Mikroc to program Embedded Systems. My basic work is on Embedded Systems. I have skills in Autocad, Proteus, C++, C programming and i love to share these skills to other to enhance my knowledge too.
3.50+
1+ Reviews
10+ Question Solved
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Question Posted:
Students also viewed these Computer science questions
-
Reimplement Fig. 17.22 using parallel streams. Use the Date/Time API timing techniques to compare the time required for the sequential and parallel versions of the program. Fig. 17.22 12345 2 3 4 13...
-
Reimplement Exercise 17.11 using parallel streams. Use the Date/Time API timing techniques to compare the time required for the sequential and parallel versions of the program. Exercise 17.11...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
The functions in Exercises 1128 are all one-to-one. For each function, a. Find an equation for f -1 (x), the inverse function. b. Verify that your equation is correct by showing that f( f -1 (x)) = x...
-
A hypothetical diatomic molecule of oxygen (mass = 2656 x 10-26kg) and hydrogen (mass = 1.67 x 10 -27 kg) emits a photon of wavelength 2.39m when it makes a transition from one vibrational state to...
-
A machine that fills shipping containers with driveway filler mix is set to deliver a mean fill weight of 70.0 pounds. The standard deviation of fill weights delivered by the machine is known to be...
-
Karen Rees, director of marketing at Woodvale Products Limited, has called an urgent meeting with her fellow directors of the other func tional areas of the business. The over riding reason for...
-
BatCo makes metal baseball bats. Each bat requires 1 kg. of aluminum at $ 18 per kg. and 0.25 direct labor hours at $ 20 per hour. Overhead is assigned at the rate of $ 40 per labor hour. What...
-
You are investing a lump sum of $7200 with a goal of saving $220,000 total in 30 years. What annual interest rate on your investments would you need to reach your goal? a. 11.8 percent b. 12.3...
-
In Fig. 17.24 , we implemented a stream pipeline that rolled a die 60,000,000 times using values produced by SecureRandom method ints. Use the same timing techniques you used in Exercise 17.25 to...
-
Describe how a highway off-ramp onto a local road is a good example of a producer/consumer relationship with a bounded buffer. In particular, discuss how the designers might choose the size of the...
-
A polar curve is given as r = cos 2 + cos . a. Show that x = cos + cos 2 - 2cos 3 . b. Differentiate the result in part a and show that for stationary points sin(6 cos 2 + cos - 1) = 0. c. Deduce...
-
Consider the situation you addressed in Problem and Exercise 3. Create numeric cost estimates for each of the costs you listed. Calculate the net present value and return on investment. Include a...
-
The output power \(\dot{W}\) of a spinning shaft is a function of torque \(T\) and angular velocity \(\omega\). Use dimensional analysis to express the relationship between \(\dot{W}, T\), and...
-
In groups of three, pick a local healthcare organization with which you are familiar. Conduct a SWOT analysis on the organization. After completing the SWOT analysis, use the template in exhibit 8.12...
-
The Dean Door Corporation (DDC) manufactures steel and aluminum exterior doors for commercial and residential applications. DDC landed a major contract as a supplier to Walker Homes, a builder of...
-
In Exercises 47 and 48, write a two-column proof. GIVENmWYZ = m/TWZ = 45 PROVE SWZ = ZXYW SW X Y N T
-
How can the loan decisions of individuals and private bankers contribute to the instability in the macroeconomy (the business cycle)? Otherwise stated, how can an uncontrolled banking system...
-
Find the APR in each of the following cases: NUMBER OF TIMES COMPOUNDED Semiannually Monthly Weekly Infinite EAR APR 10.4% 8.9 11.6 15.4
-
In the previous problem, do we need both network and data-link layers? Previous Problem Assume we have an internet (a private small internet) in which all hosts are connected in a mesh topology. Do...
-
When we talkabout the broadcast address in a link, do we mean sending a message to all hosts and routers in the link or to all hosts and routers in the Internet? In other words, does a broadcast...
-
Repeat Problem 8-12 if we use 6 crossbars at the middle stage. Problem 8-12 We need a three-stage space-division switch with N = 100. We use 10 crossbars at the first and third stages and 4 crossbars...
-
The Regal Cycle Company manufactures three types of bicyclesa dirt bike, a mountain bike, and a racing bike. Data on sales and expenses for the past quarter follow: Total Dirt Bikes Mountain Bikes...
-
?? A local college is deciding whether to conduct a campus beautification initiative that would imvolve various projects, such as planting trees and remodeling bulidings, to make the campus more...
-
A company has net income of $196,000, a profit margin of 9.7 percent, and an accounts receivable balance of $135,370. Assuming 70 percent of sales are on credit, what is the companys days sales in...
Study smarter with the SolutionInn App