Reimplement Fig. 17.22 using parallel streams. Use the Date/Time API timing techniques to compare the time required
Question:
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
Transcribed Image Text:
12345 2 3 4 13 14 15 5 import java.nio.file.Paths; 6 import java.util.Map; 7 import java.util.TreeMap; 8 import java.util. regex .Pattern; java.util.stream.Collectors; 9 import 10 II public class StreamOfLines { 12 16 17 18 19 20 NNNNN200 21 22 23 24 25 // Fig. 17.22: StreamOfLines.java // Counting word occurrences in a text file. import java.io.IOException; import java.nio.file.Files; 26 27 28 29 30 31 32 33 34 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")) .flat Map (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: 0% (1 review)
The provided image depicts Java code for a program StreamOfLines that reads a text file and counts the occurrences of each word in a sequential manner using stream operations To reimplement the code u...View the full answer
Answered By
Pushpinder Singh
Currently, I am PhD scholar with Indian Statistical problem, working in applied statistics and real life data problems. I have done several projects in Statistics especially Time Series data analysis, Regression Techniques.
I am Master in Statistics from Indian Institute of Technology, Kanpur.
I have been teaching students for various University entrance exams and passing grades in Graduation and Post-Graduation.I have expertise in solving problems in Statistics for more than 2 years now.I am a subject expert in Statistics with Assignmentpedia.com.
4.40+
3+ 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 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...
-
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 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...
-
Use the graph of f to solve Exercises 924. Where applicable, use interval notation. Find the x-intercept(s). y = f(x) # [TD y X
-
A p-n junction has a saturation current of 3.60mA. (a) At a temperature of 300 K, what voltage is needed to produce a positive current of 40.0mA? (b) For a voltage equal to the negative of the value...
-
Given the information in Exercise 10.29, construct a 99% confidence interval for the population mean, then reach a conclusion regarding whether could actually be equal to the value that has been...
-
Define partnership dissolution, and explain what accounting issues should be addressed upon dissolution. AppendixLO1
-
Fishel Company is working on two job orders. The job cost sheets show the following: Prepare the three summary entries to record the assignment of costs to Work in Process from the data on the job...
-
5.1 Call up transaction VA01 and select the field Distribution Channel. Press the F1-button. What is a distribution channel (in a few keywords)
-
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...
-
Shown here is a list of the top five semiconductor companies in the United States, along with their revenue ($ millions). Firm .. Revenue ($ millions) Intel Corp. . 49,685 Texas Instruments . 14,081...
-
Sketch the curves with equations given in question 3 parts a, b, c and d, labelling any stationary points with their coordinates. Data from Question 3 Find the coordinates of the points where the...
-
Trace the polygon and point P on paper. Then draw a rotation of the polygon the given number of degrees about P. 130 Q R T P S
-
Name any devices other than the three mentioned in Section 31. 1-battery, solar cell, and electric generator that can act as a power source in an electric circuit. Data from Section 31. 1...
-
A thick resistor and a thin resistor of the same length and material are connected in series, as shown in Figure 31. 29. Which resistor has \((a)\) the greater potential difference across it and...
-
Note that the amount of 25k that has already been spent on developing the website is not included in this analysis, as it represents a sunk cost. The decision rule for ARR is that a project should be...
-
Critics of federal banking policy argue that deposit insurance is a key reason for banking failures. The firm faces a "heads I win, tails the government loses" proposition. Several possible reforms...
-
Which of the ocean zones shown would be home to each of the following organisms: lobster, coral, mussel, porpoise, and dragonfish? For those organisms you identify as living in the pelagic...
-
Redesign the configuration of Problem 8-12 using the Clos criteria. 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...
-
In Figure 9.5, show the process of frame change in routers R1 and R2. Figure 9.5 Figure 7.5 UTP connector 12345678 2343678 RJ-45 Female RJ-45 Male
-
In Figure 9.7, do you think that system A should first check its cache for mapping from N2 to L2 before even broadcasting the ARP request? Figure 9.7 Figure 9.7 ARP operation LAN System A System B...
-
Marie Forleo, a marketing trainer and host of MarieTV, presents the eight tips for genuine networking. Do you agree or disagree with her suggestions? Discuss how this information is useful to you and...
-
Identify all relevant costs or revenue that are applicable to production- constrained decisions 1. Contributions margin of product 2. Interference with other production 3. Contribution margin per...
-
Gammaro Compary manufactures wallets from fabric. In 2 0 1 9 , Gammaro made 2 , 1 5 0 , 0 0 0 wallets using 1 , 2 5 0 , 0 0 0 yards of fabric. In 2 0 1 9 , Gammaro has capacity to make 2 , 8 0 0 , 0...
Study smarter with the SolutionInn App