Associative Arrays in Java

Java doesn’t have associative arrays as JavaScript has:

but You can accomplish this via Maps. Something like this:

To create a Map:

Map<String, String> assoc = new HashMap<String, String>();

To add a key-value pair:

assoc.put("name", "demo");

To retrieve the value associated with a key:


And sure, you may create an array of Maps:

Map<String, String>[] assoc = ...