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...
-
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.)...
-
\(\quad-2 \pi \quad-\sqrt{11} \quad-17 \quad 679 \quad \frac{14}{37} \quad \frac{57}{151}\) Correctly place the numbers in the Venn diagram. N N R
-
TipTop Flight School offers flying lessons at a small municipal airport. The schools owner and manager has been attempting to evaluate performance and control costs using a variance report that...
-
A company is selling an equipment after three years for $12,433. The equipment was originally purchased for $55,671. The tax rate is 22%. The equipment is classified as a 5-year property. What is the...
-
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...
-
Draw or construct a molecular model of the most stable conformation of 1-tert-butyl-1-methylcyclohexane.
-
A spherical shell contains three charged objects. The first and second objects have a charge of -15.0 nC and 34.0 nC, respectively. The total electric flux through the shell is -638 N-m/C. What is...
-
A tennis player moves in a straight-line path as shown in the figure below. Find her average velocity in the following time intervals. x (m) 4 2 (a) 0 to 1.0 s t(s) 2 3 4 5 m/s (b) 0 to 4.0 s m/s (c)...
-
Convert this formula to linear for y=mx+c = Eg 2kT
-
You are an assistant to Blake Harper, a partner in Parma Disaster Recovery in Atlanta, Georgia. The firm offers training and consulting services to companies that want to prepare for or recover from...
-
Discuss appropriate management of diversity, and how it can help in the areas of cost, acquisition, resources, marketing, creativity, problem solving, and flexibility?
-
Why don't codes of conduct or existing jurisprudence provide sufficient guidance for accountants in ethical matters?
-
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...
-
Define Loading Condition/Schedule in accordance with AC 43.13-1B Chapter 10, paragraph 10-18, 10-23 and FAA-H-8083-30 chapter 4.
-
This homework is to be solved using concepts from sections 7.1 to 7.7 of your textbook and other prior sections in chapters 6 and 5. Solutions that include entropy balance concepts will not be...
-
Theory of Elasticity T . G . Sitharam L . Govindaraju
Study smarter with the SolutionInn App