0

How to use a dictionary in java

I'm unsure how to use the java equivalent of a dictionary containing a key:value pair

8th Aug 2017, 1:18 PM
Robert Atkins
Robert Atkins - avatar
2 ответов
+ 2
In Java the type (interface) is called Map and implemented by few classes like HashMap, TreeMap, etc. The "correct way to define Dictionary equivalent would be: Map<KeyClass, ValueClass> mapName = new HashMap<>(); There is no Java equivalents for index access, only methods mapName.put(key, value); mapName.putAll(anotherMap); mapName.get(key)
12th Aug 2017, 2:58 PM
CAB
+ 3
A hashmap Hashmap<VarType1,VarType2> hashMap = new HashMap<>(); hashMap.add(key,value); hashMap.get(key);
8th Aug 2017, 1:18 PM
Hassie
Hassie - avatar