getOrDefault: Difference between revisions
Jump to navigation
Jump to search
(setDefault parameter was missing) |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
Line 10: | Line 10: | ||
|s1= hashMap [[getOrDefault]] [key, defaultValue, setDefault] | |s1= hashMap [[getOrDefault]] [key, defaultValue, setDefault] | ||
|p1= hashMap : [[HashMap]] | |p1= hashMap: [[HashMap]] | ||
|p2= key: [[HashMapKey]] - Case sensitive key | |p2= key: [[HashMapKey]] - Case sensitive key | ||
Line 16: | Line 16: | ||
|p3= defaultValue: [[Anything]] - (Optional, default [[nil]]) | |p3= defaultValue: [[Anything]] - (Optional, default [[nil]]) | ||
|p4= setDefault: [[Boolean]] - (Optional, default [[false]]) | |p4= 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 | ||
|p4since= arma3 2.04 | |p4since= arma3 2.04 | ||
|r1= [[Anything]] | |r1= [[Anything]] | ||
|x1= < | |x1= <sqf>private _myValue = _myHashMap getOrDefault ["a", "Not Found!"];</sqf> | ||
|x2= < | |x2= <sqf>private _myValue = _hashMap getOrDefault ["a", "Not Found!", true]; // will add default value to the hash map if it does not exist</sqf> | ||
|x3= < | |x3= <sqf> | ||
_array | private _array = _hashmap getOrDefault [_key, [], true]; // a new array will be created if it doesn't exist | ||
_array pushBack _item; // _item will be added to the array (the one in the hashmap is updated by reference) | |||
</sqf> | |||
|seealso= [[HashMap]] [[get]] | |seealso= [[HashMap]] [[get]] | ||
}} | }} |
Revision as of 13:53, 5 May 2022
Description
- 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
- Groups:
- HashMap
Syntax
- Syntax:
- hashMap getOrDefault [key, defaultValue, setDefault]
- Parameters:
- hashMap: HashMap
- key: HashMapKey - Case sensitive key
- defaultValue: Anything - (Optional, default nil)
- since 2.04
- 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
- Return Value:
- Anything
Examples
- Example 1:
- Example 2:
- Example 3:
Additional Information
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note