Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of Java's HashMap in AutoHotkey?

I have a set of abbreviated department names. I need to create a script which can map these abbreviations with their official titles. (For example: ADMIN → Administration)

In Java I could accomplish this using a HashMap.

public static void main() {
   HashMap hm = new HashMap(); // create hash map

   hm.put("ADMIN", "Administration");  // add elements to hashmap
   hm.put("RAD",   "Radiologist");
   hm.put("TECH",  "Technician");

   System.out.println("ADMIN is an abbreviation for " + hm.get("ADMIN"));
}

Is there an equivalent solution for this in AutoHotkey?

like image 269
Stevoisiak Avatar asked Oct 19 '25 10:10

Stevoisiak


1 Answers

You can implement key-value pairs using an Associative Array

An associative array is an object which contains a collection of unique keys and a collection of values, where each key is associated with one value. Keys can be strings, integers or objects, while values can be of any type. An associative array can be created as follows:

Array := {KeyA: ValueA, KeyB: ValueB, ..., KeyZ: ValueZ}

Here is an array which uses a job's shortened name (key) to find the full display name (value).

JobArray := {ADMIN:"Administration", TECH:"Technician", RAD:"Radiologist"}

; Check if key is present
if (JobArray.HasKey("ADMIN"))
    MsgBox, % "ADMIN is an abbreviation for " . JobArray["ADMIN"]
else
    MsgBox, % "No display name found"
like image 80
Stevoisiak Avatar answered Oct 22 '25 07:10

Stevoisiak