I am new to julia!I have just switched from java to julia, Can somebody tell me does julia have hashmap like structures? if No, then how do I map one type to another type in julia?
Yes!! It does have. Below is how you can create and access one inside Julia.
# Creating the Dict in Julia
julia> hashmap = Dict("language"=>"julia","version"=>"0.6")
Dict{String,String} with 2 entries:
"language" => "julia"
"version" => "0.6"
# To access individual keys
julia> hashmap["language"]
"julia"
# To find the fields inside a dictionary
julia> fieldnames(hashmap)
8-element Array{Symbol,1}:
:slots
:keys
:vals
:ndel
:count
:age
:idxfloor
:maxprobe
# To iterate over the hashmap
julia> for i in hashmap
println(i)
end
"language"=>"julia"
"version"=>"0.6"
The Julia Dict
is implemented as a hashmap. As with Java, it is important to consider the interface versus the implementation.
Associative
is an abstract type that roughly corresponds to Map
in Java; these objects can be indexed by their keys to get the corresponding values:
value = associative[key]
Dict
is a concrete subtype of Associative
that is implemented as an unordered hashmap.
dict = Dict("a" => 1, "b" => 3)
@show dict["a"] # dict["a"] = 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With