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...
-
What were three different conditions participants were placed into? Study 1 How often and for how long did participants have to journal? What were the dependent variables in this study? (What were...
-
Fill in the Blank. Univariate distributions describe the probability distributions of __________ random variables.
-
Hau Lee Furniture, Inc., described in Example 1 of this chapter, finds its current profit of $ 10,000 inadequate. The bank is insisting on an improved profit picture prior to approval of a loan for...
-
Mr . and Mrs . Klein, married without dependents, have $ 1 7 5 , 0 0 0 salaries and $ 5 0 , 0 0 0 qualified dividends on their joint tax return. The couple has itemized deductions of $ 2 9 , 0 0 0 ....
-
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...
-
Write an equation for each hyperbola. y-intercepts (0, 12); foci at (0, -15), (0, 15)
-
1. Calculate the monthly payment for a home loan of $650,000 financed at 7.5% over 15 years. 2. Calculate the monthly payment for a home loan in San Francisco of $1,500,000 financed at 8% over 30...
-
For the two completed bridge projects, Benjamin Sheares Bridge and Keppel Viaduct (after widening), please briefing describe the existing Main Structural Systems, Main Structural Materials, Main...
-
After release from rest at B, the 2 lb plug A slides down the smooth path and embeds in the 4 lbblock C. Determine the velocity of the block and embedded after engagement and find the deflection of...
-
Watertown, Inc. was founded in May, 2005 by Lawrence Rollins, who was employed for 20 years prior as a river rafting guide. Mr. Rollins received an unexpected inheritance of $2,000,000 in January,...
-
You have opened a futures account with a cash deposit of $10,000.00. You decide to sell 8 October contracts of bean meal at 305.4. Contract specs are as follows: CONTRACT UNIT 100 TONS QUOTE UNITS...
-
For each set of vectors, graph and find the x- and y-components of the resultant vectorR. NB Di
-
Dan and Diana file a joint return. Dan earned $31,000 during the year before losing his job. Diana received Social Security benefits of $5,000. a. Determine the taxable portion of the Social Security...
-
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...
-
What do you think about the effect that an equal time sharing arrangement has on the amount of child support versus an unequal time sharing arrangement, and what implications do you believe that may...
-
You are charged with choosing a topic in the field of juvenile justice for your research paper.You need to provide me with the research topic selected, as well as your associated sub-topics. Review...
-
The spread of Coronavirus started exponentially. If the total number of cases doubled every 3 days, how many days would it take to have five times the number of today's cases. You must show your...
Study smarter with the SolutionInn App