Question: Java: Modify method showIndex so each output line displays a word followed by a comma and a list of line numbers separated by commas. You

Java: Modify method showIndex so each output line displays a word followed by a comma and a list of line numbers separated by commas. You can either edit the string corresponding to each Map entry before displaying it or use methods Map.Entry.getKey and Map.Entry.getValue to build a different string. (5 points)

Java: Modify method showIndex so each output line displays a word followed

EXAMPLE 7.11 In Example 74 we showed how to use a Map to build an index for a term paper. Because we want to display the words of the index in alphabetical order, we must store the index in a SortedMap. Method showIndex below displays the string representation of each index entry in the form key value If the word fire appears on lines 4, 8, and 20, the corresponding output line would be fire [4, 8, 20] It would be relatively easy to display this in the more common form: fire 4, 8, 20 (see Programming Exercise 4). Displays the index, one word per line public void showIndex() index for Each((k, v) System.out print Inck v)); The Map. forEach method applies a Biconsumer (See Table 6.2) to each map key-value pair. In the lambda expression (k, v) System.out.println(k v) the parameter k is bound to the key, and the parameter v is bound to the value. Without Java 8, the enhanced for loop could be used but the code would be more cumbersome: Displays the index one word per line public void show Index C) for (Map.Entry

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!