I'm confused as to how to work around the null pointer exception with this object.
map.put("Baby", null);
map.put("Hugs", 111111111111L); <--------- This is also not correct, right???
Here is the code to get the value. Does toString() not work on null objects?
String value = person.getValue().toString();
I also tried to change the things put in the HashMap but it won't let you do that. Very confused.package com.codegym.task.task08.task0806;
import java.util.HashMap;
import java.util.Map;
/*
HashMap of Objects
*/
public class Solution {
public static void main(String[] args) throws Exception {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("Sim", new Integer(5));
map.put("Tom", new Double(5.5));
map.put("Arbus", new Boolean(false));
map.put("Baby", new String("Zach"));
map.put("Cat", "Cat");
map.put("Eat", new Long(56));
map.put("Food", new Character('3'));
map.put("Gevey", new Character('6'));
map.put("Hugs", new String("111111111111L"));
map.put("Comp", new Double(123));
//write your code here
for (Map.Entry<String, Object> person : map.entrySet())
{
String key = person.getKey();
String value = person.getValue().toString();
System.out.println(key + " - " + value);
}
}
}