get!(collection,key,default)

get!(collection, key, default)

Return the value stored for the given key, or if no mapping for the key is present, store key => default, and return default.

Examples

julia> dict = {"A"=>1, "B"=>2};

julia> get!(dict,"A",42)
1

julia> get!(dict,"C",42)
42

julia>  get!(dict,"D") do       # equivalent to get!(() -> 100, dict, "D");
        return 100
    end;

julia> dict
Dict{Any,Any} with 4 entries:
 "B" => 2
 "A" => 1
 "C" => 42
 "D" => 100

See Also

append!, delete!, deleteat!, empty!, endof, filter, filter!, gc, get!, getkey, haskey, insert!, isempty, keys, map, map!, merge, merge!, pop!, prepend!, push!, reduce, resize!, shift!, splice!, unshift!, values,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: