Question: Write a method that creates a list of all the values in a HashMap that are located at odd keys. You will then sort

Write a method that creates a list of all the values in a HashMap that are located at odd keys. You will then

Write a method that creates a list of all the values in a HashMap that are located at odd keys. You will then sort that list (using Collections.sort) and return the sorted list. For example, given the map: (1: "a", 2 "x, 3: "c", 4: "d"), the result should be a list with:{"a", "c"). Call this method: odd o Parameter(s): HashMap o Returns: ArrayList class HashingExercise ( // Your code here: public static void main(String[] args) { HashMap hash_map = new HashMap (): hash_map.put(1, "Diana"); hash_map.put(2, "Naomi"); hash_map.put(3, "Adam"); hash_map.put(4, "Eric"); hash_map.put(5, "Kavitha"); hash_map.put(6. "Yu"); hash_map.put(7, "Mushitaba"); hash_map.put(8, "Marisa"); hash_map.put(9, "Peter"); hash_map.put(10, "Slanovich"); // Should print: [Adam, Diana, Kavitha, Mushitaba, Peter] System.out.println(odd(hash_map]): } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Java method that takes a HashMap as input retrieves the values at odd keys sorts them and returns th... View full answer

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 Programming Questions!