Share via


Map.insert Method

Inserts an element (keyValue, valueValue pair) in the map.

Syntax

public boolean insert(anytype keyValue, anytype valueValue)

Run On

Called

Parameters

  • keyValue
    Type: anytype
    The key value.
  • valueValue
    Type: anytype
    The value mapped to by the key.

Return Value

Type: boolean
true if the key did not already exist in the map and has been inserted; otherwise, false.

Remarks

If the key already exists in the map, the value is updated.

Examples

The following example checks whether the _from map has any elements, and it creates an enumerator for the map if it has any elements. The map is traversed, and the insert method is used to insert the elements from the _from map into the _to map.

static void mergeRecsPrim( 
    Map _from, 
    Map _to 
    ) 
{ 
    MapEnumerator   me; 
  
    if (! _from) 
    { 
        return; 
    } 
 
    if (! _from.elements()) 
    { 
        return; 
    } 
 
    me = _from.getEnumerator(); 
    while (me.moveNext()) 
    { 
        _to.insert(me.currentKey(),me.currentValue()); 
    } 
}

See Also

Map Class

Map.exists Method

Map.lookup Method

Map.remove Method