KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
So I have two questions about HashMap s 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 HashMap hold 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 an int as a value, in the second an int[] , and third a string. Is this okay to do in Java with HashMap s? Also, is it okay to store a HashMap as a value within a HashMap ?
Tags (comma-separated)
Save Edits
Cancel