Question: Using the Java library tools you have learned this semester (see code handout) implement the function printDecrSize which when given a Map whose keys

Using the Java library tools you have learned this semester (see code handout) implement the function printDecrSize which when given a Map whose keys are type string and whose values are type ArrayList , prints all the entries in decreasing order by the size of their lists (ones with the same size can appear in any order). The method will not modify the given Map. For example, if the map had the following five entries (shown below in Map's toString format): {cceilr=[circle, cleric], hi=[hi], eiflr=[filer, flier, lifer, rifle], adn [and], chin= [inch, chin]} the output of calling print DecrSize on such a Map might be: eiflr: [filer, flier, lifer, rifle] chin: [inch, chin] cceilr: [circle, cleric] adn: [and] hi: [hi] i.e., entries in decreasing order by the size of their lists Hint: format for each ArrayList in the answer is just the normal tostring format. public static void print DecrSize (Map map) { [Java] Map Interface (selected methods) The classes that implement this interface are: TreeMap and HashMap. ValueType put (key, value) Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced by the specified value. Returns the previous value associated with specified key, or null if there was no mapping for key. ValueType get (key) Returns the value to which this map maps the specified key or null if the map contains no mapping for this key. boolean containsKey(key) Returns true iff the map contains a mapping for the specified key. ValueType remove (key) Removes the mapping for this key from this map if it is present, otherwise returns null. int size() boolean isEmpty() Number of key-value mappings in this map. Returns true if this map contains no key-value mappings. Set entrySet() Returns a set view of the entries contained in this map. Set keySet() Returns a set view of the keys contained in this map. [Java] Map. Entry Interface KeyType getKey() ValueType getValue() void setValue (newVal) Return the key of the entry Return the value of the entry Replace the current value with newVal
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
