So I have two questions about HashMaps in Java:
What is the correct way to initialize a
HashMap? I think it might be best in my situation to use:HashMap x = new HashMap();But Eclipse keeps suggesting that I use:
HashMap<something, something> map = new HashMap();Which is better?
Can a
HashMaphold different types of objects/data types as values? For example, would this work and be OK:map.put("one", 1); map.put("two", {1, 2}); map.put("three", "hello");In the first
put(), I want anintas a value, in the second anint[], and third a string. Is this okay to do in Java withHashMaps? Also, is it okay to store aHashMapas a value within aHashMap?