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: 100% (QA)
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...
-
What is the 80/20 rule, and how does it apply to total quality management?
-
On March 13, 1963, Ernesto Miranda was arrested for kidnapping and rape and taken to a Phoenix police station. After being identified by the complaining witness, he was questioned by two police...
-
Here are comparative balance sheets for Taguchi Company. Additional information:1. Net income for 2010 was $103,000.2. Cash dividends of $45,000 were declared and paid.3. Bonds payable amounting to...
-
K Use appropriate formulas to find (a) the perimeter and (b) the area of the figure. 8.8 m 5 m 5.2 m 7 m (a) The perimeter is (Type an integer or a decimal.)
-
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...
-
Consider the two dimensional map \[x_{n+1}=\alpha\left(x_{n}-\frac{1}{4}\left(x_{n}+y_{n} ight)^{2} ight) \quad, \quad y_{n+1}=\frac{1}{\alpha}\left(y_{n}+\frac{1}{4}\left(x_{n}+y_{n} ight)^{2}...
-
Given the following optimal LP tableau of a cost minimization problem, determine the value of the decision variables of an MIP with the following constraints: x1, x3 = +Integers x2 > 0 -Z 0 0.692308...
-
Tunneling L2 traffic over a L3 network is an example of a(n) 3-tier campus redundant star spine-leaf O overlay/underlay topology.
-
Below is the balance sheet for Loser, Inc. Loser, Inc. is an insolvent company in bankruptcy that is about to be liquidated under Chapter 7 of the bankruptcy code. All of the asset values on the...
-
Mr. Jordon Lake is an administrator for a publicly traded Canadian manufacturing company. His gross salary for the year ending December 31, 2017 is $83,000. For the 2017 taxation year, Mr. Lake's...
-
There are four main components associated with the cost of turnover: separation costs, vacancy costs, replacement costs, and training costs. Kindly explain what is the most expensive and why.
-
The following procedures were recently installed by Pancreas Company: a. At the end of each day, an accounting clerk compares the duplicate copy of the daily cash deposit slip with the deposit...
-
A report from the college dean indicates that for the previous semester, the grade distribution for the Department of Psychology included 135 As, 158 Bs, 140 Cs, 94 Ds, and 53 Fs. Determine what kind...
-
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...
-
What are the most important steps for a paralegal in preparing for an initial client interview with a new Family Law Firm client? Why are attorney supervision and client confidentiality so important...
-
In a study of Van der Waals forces between particles and surfaces, Electric double layer forces, DLVO forces, Polymer-mediated steric forces, and Depletion forces: 1. Derive an expression for the...
-
Lott Company uses a job order cost system and applies overhead to production on the basis of direct labor costs. On January 1, 2022, Job 50 was the only job in process. The costs incurred prior to...
Study smarter with the SolutionInn App