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...
-
Convert each of the following indexes so that the new base period will be 1997. 1994 101.3 100.0 1995 100.0 102.9 1996 103.4 104.7 105.6 1997 103.2 1998 107.9 107.5 1999 110.3 126.4 2000 116.2 122.1...
-
Robert Carr is the founder of Heartland Payment Systems, Inc. Carr was heavily involved in negotiations with Global Payments, Inc., concerning the acquisition of Heartland by Global. During this...
-
A cotton grower in south Georgia produces cotton on farms in Statesboro and Brooklet, ships it to cotton gins in Claxton and Millen, where it is processed, and then sends it to distribution centers...
-
Assignment - Preschool YearsOverview The early childhood years are filled with many social and emotional developmental changes. Understanding the developmental theories in early childhood and...
-
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...
-
What are the five steps involved in employing process costing?
-
Overview Dynamic pricing is a collection of pricing strategies used by firms and organizations to enhance profits. You will begin by exploring pricing techniques that operate in the market in real...
-
? ? The task is to create a NoSQL database for a library to manage its book records. Task 1 . 1 1 . 1 Write a python program to: Create a MongoDB database named library and a new collection named...
-
a. Write the binary string for the message "hello friends". How many bits are needed for Huffiman code? How many bits are needed for ASCII code? b. Decode the following binary string using the above...
-
You have configured LDAP over SSL (LDAPS) with default settings to secure directory service queries across subnets. Which port must be open on the subnet firewall?
-
We have engaged in several excellent discussions over the semester. For this discussion, post a farewell to your colleagues and offer them bit of knowledge, advice, even a joke. Then check out a few...
-
The cash account for Pickron Co. at April 30, 2006, indicated a balance of $13,290.95. The bank statement indicated a balance of $18,016.30 on April 30, 2006. Comparing the bank statement and the...
-
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...
-
The following financial statement information is from five separate companies. Beginning of year Assets Liabilities End of year Assets Liabilities Changes during the year Stock issuances Net income...
-
Fence Inc completed job 1 5 on November 3 0 . The details of job 1 5 are given below. Direct labor cost 8 5 0 , direct materials cost 1 0 0 0 , machine hiurs 8 direct labor hours 2 4 predrermine...
-
What happens when a company purchases investments classified as trading securities?
Study smarter with the SolutionInn App