logo

How to Define an Array by Specifying Its Type in Julia 📂Julia

How to Define an Array by Specifying Its Type in Julia

Code

To specify the type in front of the brackets, simply write the type name.

julia> [1, 2, 3]
3-element Vector{Int64}:
 1
 2
 3

julia> Float64[1, 2, 3]
3-element Vector{Float64}:
 1.0
 2.0
 3.0

julia> Complex{Float64}[1, 2, 3]
3-element Vector{ComplexF64}:
 1.0 + 0.0im
 2.0 + 0.0im
 3.0 + 0.0im

julia> Char[1, 2, 3]
3-element Vector{Char}:
 '\x01': ASCII/Unicode U+0001 (category Cc: Other, control)
 '\x02': ASCII/Unicode U+0002 (category Cc: Other, control)
 '\x03': ASCII/Unicode U+0003 (category Cc: Other, control)

Environment

  • OS: Windows11
  • Version: Julia 1.10.0