Is it possible in Java to make a Dictionary with the items already declared inside it? Just like the below C# code:
Dictionary d = new
Bite the bullet and type out the map name!
Map map = new HashMap();
map.put("cat", 2);
map.put("dog", 1);
map.put("llama", 0);
map.put("iguana", -1);
You could also do something like this, which might save some typing with a long list:
Object[][] values = {
{"cat", 2},
{"dog", 1},
{"llama", 0},
{"iguana", -1}
};
for (Object[] o : values) {
map.put((String) o[0], (Integer) o[1]);
}