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

Hash Maps A hashtable is a data structure that allows the user to look up things

ID: 3832626 • Letter: H

Question

Hash Maps A hashtable is a data structure that allows the user to look up things by a key value. Java implements a hashtable called "HashMap". The way it works is to specify two types of classes. One is the "key", and another is the "value". You can put data values into the HashMap at an "index" specified by the key Like Array List, HashMap is a generic class, so you declare it using angle brackets. For HashMap, you must include both the key type and the value type in this declaration, so the declaration looks like HashMap

Explanation / Answer

public class Lab7b

{  public static void main(String args[])

{ HashMap<String,Integer> songsstars = new HashMap<String,Integer>(); // inserted code

songstars.put(" the ballad of bilbo baggins ",5);

songstars.put(" A still more glorious dawn ",4);

songstars.put(" a finest simple group of oprder two",4 );

songstars.put("code monkey', 4);

songstars.put("fish heads",2);

songstars.put("I'll form the head",3);

songstars.put(" Honetbee",5);

songstars.put(" silver apples of the moon",4);

// get the number of starbs for "code monkey" and print here

System.out.println(get the number of stars for code monkey is :" + songstars.get("Code monkey") );

// remove honeybee

songstars.remove("Honeybee");

// inserted code determine if Honeybee is in table print " Honeybee still in the table"

// else print " Honeybee successfully removed from the tablein the table"

if(songstars.containskey("Honeybee"))

{System.out.println(" Honeybee still in the table");  

}

else

{

System.out.println(" Honeybee successfully removed from the tablein the table");

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote