# What should the first parameter be when collecting keys from a dictionary?

**URL:** <https://discourse.julialang.org/t/what-should-the-first-parameter-be-when-collecting-keys-from-a-dictionary/49245>\
**Category:** New to Julia\
**Created:** [October 29, 2020, 3:38pm UTC](https://discourse.julialang.org/t/what-should-the-first-parameter-be-when-collecting-keys-from-a-dictionary/49245 "2020-10-29T15:38:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon60034542](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@anon60034542](https://discourse.julialang.org/u/anon60034542)\
**Post date:** [October 29, 2020, 3:38pm UTC](https://discourse.julialang.org/t/what-should-the-first-parameter-be-when-collecting-keys-from-a-dictionary/49245/1 "2020-10-29T15:38:45Z")

</div>

When using [collect()](https://docs.julialang.org/en/v1/base/collections/#Base.collect-Tuple%7BType,Any%7D), it requires two parameters, the element type and the collection.

When you’re creating an array from dictionary keys what should the element type parameter be?

```julia
character_inventory = Dict{String,Int32}("Sword" => 100, "Staff" => 50)
character_inventory_keys = keys(character_inventory)
 # Prints Base.KeySet{String,Dict{String,Int32}}
println(typeof(character_inventory_keys))
println(collect(character_inventory_keys))

```

If I place `KeySet{String,Dict{String,Int32}}` as the first parameter it produces an error.

I’m aware that I don’t necessarily need the type, I can just call `collect(character_inventory_keys)` but in the interest of learning, I thought I would ask.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [October 29, 2020, 3:42pm UTC](https://discourse.julialang.org/t/what-should-the-first-parameter-be-when-collecting-keys-from-a-dictionary/49245/2 "2020-10-29T15:42:55Z")

</div>

The first parameter is the element type of the resulting container, but if you omit it Julia will use the default element type of the iterator:

```julia
julia> character_inventory = Dict{String,Int32}("Sword" => 100, "Staff" => 50)
Dict{String,Int32} with 2 entries:
  "Sword" => 100
  "Staff" => 50

julia> collect(character_inventory)
2-element Array{Pair{String,Int32},1}:
 "Sword" => 100
 "Staff" => 50

```

but you could collect to e.g. `Pair{String,Int64}` if you want:

```julia
julia> collect(Pair{String,Int64}, character_inventory)
2-element Array{Pair{String,Int64},1}:
 "Sword" => 100
 "Staff" => 50

```
