How do I check if an array is empty in Julia?

From Julia help: isempty determines whether a collection is empty (has no elements).

e.g.

julia> isempty([])
true

julia> isempty(())
true

In Julia you can use the isempty() function documented here.

julia> a = []
0-element Array{Any,1}

julia> isempty(a)
true

julia> length(a)
0

julia> b = [1]
1-element Array{Int64,1}:
 1

julia> isempty(b)
false

Note that I included the length check as well in case that will help your use case.


For arrays one can also simply use a == []. The types are ignored in this comparison (as usual).

julia> a = []
a == []
0-element Array{Any,1}

julia> a == []
true

julia> a == Int[]
true

julia> String[] == Int[]
true

Tags:

Julia