---
name: "merge"
type: command
status: ok
groups: ["HashMap"]
arma3_since: "2.02"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/merge
revid: 347592
updated: 2023-09-28T20:05:03Z
---

# merge

*Command · HashMap · Arma 3 v2.02*

## Description

Merges two [HashMap](../topics/HashMap.md)s.

## Syntax

### Syntax 1

```sqf
hashMap1 merge hashMap2
```

**Parameters:**

- `hashMap1`: [HashMap](../topics/HashMap.md) - this HashMap will be modified
- `hashMap2`: [HashMap](../topics/HashMap.md) - all key-value pairs from this HashMap are added to *hashMap1*. If a key from *hashMap2* already exists in *hashMap1*, it doesn't overwrite the value in *hashMap1*.

**Returns:** [Nothing](../topics/Nothing.md)

### Syntax 2

```sqf
hashMap1 merge [hashMap2, overwriteExisting]
```

**Parameters:**

- `hashMap1`: [HashMap](../topics/HashMap.md) - this HashMap will be modified
- `hashMap2`: [HashMap](../topics/HashMap.md) - all key-value pairs from this HashMap are added to *hashMap1*
- `overwriteExisting`: [Boolean](../topics/Boolean.md) - (Optional, default [false](../commands/false.md)) if [true](../commands/true.md), keys from *hashMap1* that also exist in *hashMap2* are overwritten. When set to [true](../commands/true.md), merging is faster

**Returns:** [Nothing](../topics/Nothing.md)

## Examples

### Example 1

```sqf
_hashMap merge _otherHashMap;
```

### Example 2

```sqf
private _hashmap1 = ["cow", "cat", "chicken"] createHashMapFromArray [100, 200, 200];
private _hashmap2 = ["cow", "cat", "chicken", "camel"] createHashMapFromArray [150, 300, 400, 800];
_hashmap1 merge _hashmap2; // _hashmap is [["cow",100],["cat",200],["chicken",200],["camel",800]]
```

### Example 3

```sqf
private _hashmap1 = ["cow", "cat", "chicken"] createHashMapFromArray [100, 200, 200];
private _hashmap2 = ["cow", "cat", "chicken", "camel"] createHashMapFromArray [150, 300, 400, 800];
_hashmap1 merge [_hashmap2, true]; // _hashmap is [["cow",150],["cat",300],["chicken",400],["camel",800]]
```

### Example 4

```sqf
private _hashmap1 = ["cow", "cat", "chicken"] createHashMapFromArray [100, 200, 200];
private _hashmap2 = ["cow", "cat", "chicken", "camel"] createHashMapFromArray [150, 300, 400, 800];
_hashmap1 merge [_hashmap2, false]; // _hashmap is [["cow",100],["cat",200],["chicken",200],["camel",800]] as Syntax 1
```

## See also

[insert](../commands/insert.md) · [set](../commands/set.md)

<sub>Source: [BI Community Wiki — merge](https://community.bistudio.com/wiki/merge) (revision 347592).</sub>
