Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

s Assume that you want to create a HashMap object named Cars with the following

ID: 3839483 • Letter: S

Question

s Assume that you want to create a HashMap object named Cars with the following key-value Value 2378 E012 Chevy Lumina 1796 2012 Dodge Durango Sport 3282 2013 Pontiac Grand Prix 1967 2013 Honda Accord LX Given the following API specifications for class HashMap. Constructor (for HashMap) HashMap construets an empty HashMap with the default initial capacit Method Summary (for HashMap): Removes all of the mappings from this map. containsKey (obleet key) Returns true if this map contains a mapping for the speaified entrySet Returns a set view of the mappings contained in this map. get (9bleet key) Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key keyset Returns a set view of the keys contained in this map. eut (K key, V value) Associates the specified value with the specified key in this Returns the number of key-value mappings in this nap. Collec values Returns a Collection view of the values contained in this map. Method Summary (for Map.Entry): getKey Retums the key corresponding to this entry. getValue Retums the value corresponding to this entry. set value (v value) Replaces the value corresponding to this entry with the specified value (optional operation).

Explanation / Answer

5.1)

HashMap<Integer,String> hmCars=new HashMap<Integer,String>();

_________________

5.2)

       hmCars.put(2378,"2012 Chevy Lumina");
       hmCars.put(1796,"2012 Dorge Durango Sport");
       hmCars.put(3282,"2013 Pontiac Grand Prix");
       hmCars.put(1967,"2013 Honda Accord LX");

_________________

5.3)

String description=hmCars.get(1796);

_________________

5.4)

       for(Map.Entry<Integer,String> me:hmCars.entrySet())
       {
           System.out.println(me.getKey()+": "+me.getValue());
       }

___________________

5.5)

hmCars.clear();

__________________Thank You