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...
-
Given this ANOVA summary table, write the results in APA format using α = .05. (Use df Between and df Within to find F cv in order to determine if the null hypothesis was rejected.)...
-
\(14+38.9=38.9+14\) Identify the property of real numbers that is being illustrated.
-
Assume that a resource used by activities e, f, g, and h in the figure below is scarce. To which activity would you assign the resource, based on the following rules? a. Minimum slack b. Most...
-
Person is planning to open a savings account with the intent to buy a house in 8 years. they will invest an equal amount each month for 8 years. the account will earn 9% annually and will have...
-
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...
-
An uncrowned straight-bevel pinion has 22 teeth, a module of 4 mm, and a transmission accuracy number of 5. The pinion and the gear are made of through-hardened steel, both having core and case...
-
Consider the energy we use everyday in routine tasks, where that energy comes from, and where it goes. When you walk up a hill you overcome the force of gravity to raise yourself higher against the...
-
James Company is paid $6,000 in dividends from Mark Corp. on its equity investment. James lacks significant influence over Mark Corp. James Company should debit investment in trading securities debit...
-
Discussed service quality management and the link between service quality and financial success. Which company was used as an example?
-
Find the complex root ( - 2 + - 4 ???? )
-
The Natural Museum has been celebrating the life of Thomas Young. They develop a Young's experiment display. The museum has purchased a blue laser which emits light with a wavelength of 473nm. They...
-
What is meant by the term "fiduciary relationship"?
-
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 are some important things to remember when adding instruments and supplies into a sterile field? Multiple select question. Wash your hands and then carefully place and arrange the items on the...
-
Bloomberg Market Concepts 2024 Bloomberg L.P. UTLINE Choose Your Language Regulation and Control Types of Regulation and Control Market Control International Trade Practice: Using Bloomberg Knowledge...
-
provision included in group disability income contracts but NOT included in an individual disability income contract is the: A. entire contract provision 3. rehabilitation provision C. . probationary...
Study smarter with the SolutionInn App