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...
-
Prepare a debt amortization schedule for a bond issued at discount. Assume that the bond matures in 12 years with market interest rate at time of issue-10% annually and 5% semiannually. The stated...
-
The marginal density function of \(x\) can be determined form the bivariate density function \(p(x, y)\) as a. \(p(x)=\int_{-\infty}^{\infty} p(x, y) d y\) b. \(p(x)=\int_{-\infty}^{\infty} p(x, y) d...
-
Santa Fe Corporation produces and sells a single product. Expected sales for September are 12,000 units; for October, 15,000 units; for November, 9,000 units; for December, 10,000 units; and for...
-
Refer to the following lease amortization schedule. The 1 0 payments are made annually starting with the beginning of the lease. Title does not transfer to the lessee and there is no purchase option...
-
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...
-
Office supplies were sold by Janer's cleaning service at cost to another repair shop, with cash received. Which of the following entries for Janer's Cleaning Service records this transaction? 1.Dr...
-
(a) Consider the the figure below: two-dimensional Laplace equation in a square domain, as illustrated in aU au ax + with the boundary conditions given by: U(x,0) = 0, ay U(0, y) = 2y U (0, y) = 2y,...
-
Two developers in Dallas, TX are developing a tract of land where they plan to build 30 new single-family homes, specifically 20 3-bedroom homes and 10 4-bedroom homes. The target market is the...
-
Prepare T-Accounts Date February 1 Cash Description T. Michaels, Capital February 3 Office Supplies Accounts Payable February 4 Building Land Cash February 8 Cash Service Revenue February 10 Accounts...
-
Make a network schedule(diagram) for the preparation and holding of the seasonal fair "Schools of the last moment" The chairman of the board of the department store decided to hold a seasonal fair...
-
b) Find the general and definite solutions of the first order differential equations (i) dy/dt +2y=2 y(0)=7 dy/dt - 9y=10 y(0)=11 dy/dt+y=5 y(0)=1/5 dy/dt+4y= 1/3 y(0) = 9 dy/dt +3y=-3 y(0)=12 (vi)...
-
For each set of vectors, graph and find the x- and y-components of the resultant vectorR. B.
-
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...
-
Cedric seeks your advice. Cedric has served a Claim and Statement of Claim on Liu Kwok Wah ("KW") almost 90 days ago for an action commenced in the District Court at Brisbane in relation to a breach...
-
Ace Cosmetics Corporation purchased land adjacent to its plant to improve access for trucks making deliveries. Expenditures incurred in purchasing the land were as follows: purchase price, $55,000;...
-
Find the volume of revolution V about the x-axis for the given function and interval. f(x) = x5/3, [1, 5]
Study smarter with the SolutionInn App