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
2 Respuestas
+ 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)
+ 3
A hashmap
Hashmap<VarType1,VarType2> hashMap = new HashMap<>();
hashMap.add(key,value);
hashMap.get(key);