getOrDefault: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(param)
(added example and improved new param description)
Line 17: Line 17:
|p3= defaultValue: [[Anything]] - (Optional, default [[nil]])
|p3= defaultValue: [[Anything]] - (Optional, default [[nil]])


|p4= setDefault: [[Boolean]] - (Optional, default [[false]]) - If value does not exist, '''defaultValue''' will be added to the Hash Map {{Since|arma3|2.04|y}}
|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 {{Since|arma3|2.04|y}}


|r1= [[Anything]]
|r1= [[Anything]]


|x1= <code>[[private]] _myValue = _myHashMap [[getOrDefault]] ["a", "Not Found!"];</code>
|x1= <code>[[private]] _myValue = _myHashMap [[getOrDefault]] ["a", "Not Found!"];</code>
|x2= <code>[[private]] _myValue = _hashMap [[getOrDefault]] ["a", "Not Found!", [[true]]]; {{cc|Will add default value to the hash map if it does not exist}}</code>


|seealso= [[HashMap]] [[get]]
|seealso= [[HashMap]] [[get]]
}}
}}

Revision as of 11:43, 16 March 2021

Hover & click on the images for description

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]
Parameters:
hashMap : HashMap
key: HashMapKey
defaultValue: Anything - (Optional, default nil)
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 Template:Since
Return Value:
Anything

Examples

Example 1:
private _myValue = _myHashMap getOrDefault ["a", "Not Found!"];
Example 2:
private _myValue = _hashMap getOrDefault ["a", "Not Found!", true]; // Will add default value to the hash map if it does not exist

Additional Information

See also:
HashMap get

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