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
If you use the Guava library, you can use its ImmutableMap class, either by itself (examples 1 and 2), or as an initializer for a HashMap (examples 3 and 4):
Map map1 = ImmutableMap. builder()
.put("cat", 2)
.put("dog", 1)
.put("llama", 0)
.put("iguana", -1)
.build();
Map map2 = ImmutableMap.of(
"cat", 2,
"dog", 1,
"llama", 0,
"iguana", -1
);
Map map3 = Maps.newHashMap(
ImmutableMap. builder()
.put("cat", 2)
.put("dog", 1)
.put("llama", 0)
.put("iguana", -1)
.build()
);
Map map4 = Maps.newHashMap( ImmutableMap.of(
"cat", 2,
"dog", 1,
"llama", 0,
"iguana", -1)
);