{"name":"getOrDefault","operator":null,"title":"getOrDefault","type":"command","url":"https://community.bistudio.com/wiki/getOrDefault","revid":348340,"updated":"2023-11-08T12:59:48Z","groups":["HashMap"],"status":"ok","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"2.02"}],"since":{"game":"arma3","name":"Arma 3","version":"2.02"},"arma3_since":"2.02","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"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]","since":null,"effect":null,"exec":null,"params":[{"name":"hashMap","type":"HashMap","optional":false,"default":null,"description":null,"types":["HashMap"],"since":null,"text":"hashMap: HashMap"},{"name":"key","type":"HashMapKey","optional":false,"default":null,"description":"case sensitive key","types":["HashMapKey"],"since":null,"text":"key: HashMapKey - case sensitive key"},{"name":"defaultValue","type":"Anything","optional":true,"default":"nil","description":null,"types":["Anything"],"since":null,"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","types":["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","types":["Anything"],"description":null,"text":"Anything"},"form":"binary","operator":null,"left":{"text":"hashMap","types":["HashMap"]},"right":{"text":"[key, defaultValue, setDefault]","types":["Array"]}}],"examples":[{"text":"```sqf\nprivate _myValue = _myHashMap getOrDefault [\"a\", \"Not Found!\"];\n```","code":["private _myValue = _myHashMap getOrDefault [\"a\", \"Not Found!\"];"]},{"text":"```sqf\nprivate _myValue = _hashMap getOrDefault [\"a\", \"Not Found!\", true]; // will add default value to the hash map if it does not exist\n```","code":["private _myValue = _hashMap getOrDefault [\"a\", \"Not Found!\", true]; // will add default value to the hash map if it does not exist"]},{"text":"```sqf\nprivate _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)\n```","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)"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["getOrDefaultCall","HashMap","get"],"notes":[],"categories":["Arma 3: New Scripting Commands","Arma 3: Scripting Commands","Command Group: HashMap","Introduced with Arma 3 version 2.02","Scripting Commands"]}