Write a method that creates a list of all the values in a HashMap that are...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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<Integer, String> 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]): } } 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<Integer, String> 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]): } }
Expert Answer:
Answer rating: 100% (QA)
Java method that takes a HashMap as input retrieves the values at odd keys sorts them and returns th... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
The following information from Incomplete Ltd's as at December 2019 standardised statement of financial position and statement of comprehensive income are provided to you: STATEMENT OF FINANCIAL...
-
How do you simplify the max method in the following, using the conditional operator? 1: /** Return the max of two numbers */ 2: public static int max ( int num1, int num2 ) { 3: int result; 4: 5: if...
-
Write a program that prints the calendar for a given year. The user will be promoted tochoose the calendar for the month or the year. If the year is selected, then the calendar for thegiven year will...
-
A corporate entity has both preferred and common classes of shares. How is the book value of common shares calculated in this case? What is meant by the liquidation value of preferred shares?
-
A helium-filled balloon is tied to a 2.00-m-long, 0.050 0-kg uniform string. The balloon is spherical with a radius of 0.400 m. When released, it lifts a length h of string and then remains in...
-
Explain the nature of the dilemma for Helen using the AICPA Code as a guide. What steps should she take to resolve the issue?
-
A brand-new sleeve bearing has been installed in a machine. The vibration levels on restart of the machine are not within tolerance, and the predominant peaks are at exactly one-half the operating...
-
Update the trial balance for Kylers Moving Co. (Figure) for January 31, 201X. Adjustment Data to Update Trial Balance a. Insurance expired, $550. b. Moving supplies on hand, $700. c. Depreciation on...
-
Nantucket Industries manufactures and sells two models of watches, Prime and Luxuria. It expects to sell 3,300 units of Prime and 2,000 units of Luxuria in 2019.The following estimates are given for...
-
Classic Construction Company specializes in constructing buildings with a period-correct architectural style. Three of their current projects, one in Dallas, one in St. Louis, and one in Atlanta, all...
-
If the range of a set is 20, find a rough approximation to the standard deviation of the data set.
-
You buy a new car and finance the complete cost of $25,000 with a car loan from a local dealership, without an institutional lender. The loan carries an annual interest rate of 5.0%, payable in...
-
Assume that you have Portfolio Revenue Stream of $10,000,000 and charge a Management Fee of 5% with a Valuation Multiple of 7.5x, calculate the Management Fee Stream Value.
-
According to Aristotelian rhetoric, forensic speaking as a form of persuasive discourse aims at providing praise and blame of the noble and shameful in the present accusation and defense about past...
-
A new project is expected to generate $1,500,000 in revenues, $550,000 in cash operating expenses, and depreciation expense of $300,000 in each year of its 10-year life. The corporation's tax rate is...
-
A banker wants to retire 20 years from today and would like to have an annual income of $300,000 withdrawn at the end of each year for 10 years starting in exactly 20 years. The discount rate is 6%....
-
Discuss the SOURCES OF ERROR that affect the quality of GPS observation
-
Use translations to graph f. f(x) = x-/2 +1
-
Describe the LUP decomposition of a diagonal matrix.
-
Suppose that a weighted, directed graph G = (V, E) has a negative-weight cycle. Give an efficient algorithm to list the vertices of one such cycle. Prove that your algorithm is correct.
-
Write pseudocode for a procedure that creates an empty van Emde Boas tree.
-
A crystal sample of bacteriorhodpsin, a light-sensitive protein found in halobacteria that responds to light energy, has crystal planes separated by 0.20 nm. If a beam of 11 keV x rays illuminates a...
-
A nickel crystals work function is measured to be 5.22 eV at 25C. As the temperature increases by 300C, the work function drops by 50 meV. By how much does this shift the threshold wavelength for...
-
Investigators have created structures consisting of linear chains of ionized atoms on a smooth surface. Electrons are restricted to travel along the chain. The energy levels of the electrons match...
Study smarter with the SolutionInn App