{"name":"getOrDefault","title":"getOrDefault","type":"command","url":"https://community.bistudio.com/wiki/getOrDefault","revid":348340,"updated":"2023-11-08T12:59:48Z","groups":["HashMap"],"status":"ok","games":{"arma3":"2.02"},"since":"arma3 2.02","arma3_since":"2.02","description":"Retrieves a value out of a HashMap after looking it up by its key. When the HashMap doesn't contain the key, the default value is returned","syntaxes":[{"syntax":"hashMap getOrDefault [key, defaultValue, setDefault]","params":[{"name":"hashMap","type":"HashMap","type_expr":"HashMap"},{"name":"key","type":"HashMapKey","description":"case sensitive key","type_expr":"HashMapKey"},{"name":"defaultValue","type":"Anything","optional":true,"default":"nil","type_expr":"Anything","text":"defaultValue: Anything - (Optional, default nil)"},{"name":"setDefault","type":"Boolean","optional":true,"default":"false","description":"if set to true and value does not exist in provided hash map, *defaultValue* will be added to the hash map","type_expr":"Boolean","since":"arma3 2.04","text":"setDefault: Boolean - (Optional, default false) if set to true and value does not exist in provided hash map, *defaultValue* will be added to the hash map"}],"returns":{"type":"Anything","type_expr":"Anything"},"form":"binary","left":{"text":"hashMap"},"right":{"text":"[key, defaultValue, setDefault]"}}],"examples":[{"code":["private _myValue = _myHashMap getOrDefault [\"a\", \"Not Found!\"];"]},{"code":["private _myValue = _hashMap getOrDefault [\"a\", \"Not Found!\", true]; // will add default value to the hash map if it does not exist"]},{"code":["private _array = _hashmap getOrDefault [_key, [], true]; // a new array will be created if it doesn't exist\n_array pushBack _item; // _item will be added to the array (the one in the hashmap is updated by reference)"]}],"see_also":["getOrDefaultCall","HashMap","get"]}