findOrInsert Method

Obtains the value associated with the specified key, or inserts it if the specified key does not yet exist.

findOrInsert(key: K, value: V): { inserted: boolean, value: V }

Parameter Type Description
key K The key to search for.
value V The value to associate with key if key does not yet exist in the dictionary.

Returns - { inserted: boolean, value: V }

The found or inserted value and a flag indicating whether the new value was inserted.

Defined in

Last Updated: 02 July, 2021