Task

The goal is to create an associative array (also known as a dictionary, map, or hash).



Related tasks:

 Associative arrays/Iteration
 Hash from two arrays


See also

 Array
 Associative array: Creation, Iteration
 Collections
 Compound data type
 Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
 Linked list
 Queue: Definition, Usage
 Set
 Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal
 Stack


 
using Gee;
 
void main(){
    var	map = new HashMap<string, int>(); // creates a HashMap with keys of type string, and values of type int                                                
 
    // two methods to set key,value pair
    map["one"] = 1;
    map["two"] = 2;
 
    map.set("four", 4);
    map.set("five", 5);
 
    // two methods of getting key,value pair
    stdout.printf("%d\n", map["one"]);
 
    stdout.printf("%d\n", map.get("two"));
}
 