Question & Answer: A HashMap stores values into the hash-table based on a hash for the key and a value. Write a functio…..

A HashMap stores values into the hash-table based on a hash for the key and a value. Write a function to retrieve a key/value from a HashMap.

Expert Answer

 

import java.util.collection;
import java.util.Hashmap;
import java.util.Map;

public class HashMapValDemo
{
public static void main(String[] args)
{
Map<Integer,String> map = new HashMap<Integer,String>();
map.put(1,”W”);
map.put(2,”X”);
map.put(3,”Y”);
map.put(4,”Z”);
System.out.println(map);
Collection<String> values = map.values();
for (String string : values)
{
System.out.println(String);
}
}
}

Still stressed from student homework?
Get quality assistance from academic writers!