Java Reference
In-Depth Information
16. How do you perform a union operation on two sets? An intersection? Try to give an answer that doesn't require any
loops.
Section 11.3: Maps
17. Write the code to declare a Map that associates people's names with their ages. Add mappings for your own name
and age, as well as those of a few friends or relatives.
18. A Map doesn't have the get and set methods that an ArrayList has. It doesn't even have an iterator method like a
Set does, nor can you use a for-each loop on it directly. How do you examine every key (or every value) of a Map ?
19. What keys and values are contained in the following map after this code executes?
Map<Integer, String> map = new HashMap<Integer, String>();
map.put(7, "Marty");
map.put(34, "Louann");
map.put(27, "Donald");
map.put(15, "Moshe");
map.put(84, "Larry");
map.put(7, "Ed");
map.put(2350, "Orlando");
map.remove(8);
map.put(5, "Moshe");
map.remove(84);
map.put(17, "Steve");
20. What keys and values are contained in the following map after this code executes?
Map<Integer, String> map = new HashMap<Integer, String>();
map.put(8, "Eight");
map.put(41, "Forty-one");
map.put(8, "Ocho");
map.put(18, "Eighteen");
map.put(50, "Fifty");
map.put(132, "OneThreeTwo");
map.put(28, "Twenty-eight");
map.put(79, "Seventy-nine");
map.remove(41);
map.remove(28);
map.remove("Eight");
map.put(86, "Eighty-six");
map.put(98, "Ninety-eight");
map.remove(18);
21. Modify the WordCount program so that it prints the most frequently occurring words sorted by number of occur-
rences. To do this, write code at the end of the program to create a reverse map from counts to words that is based on
the original map. Assume that no two words of interest occur the exact same number of times.
 
Search WWH ::




Custom Search