Getting an array of all items of a collection in Julia – collect() Method
Last Updated :
26 Mar, 2020
The collect()
is an inbuilt function in julia which is used to return an array of all items in the specified collection or iterator.
Syntax:
collect(collection)
or
collect(element_type, collection)
Parameters:
- collection: Specified collection or iterator.
- element_type: Specified type of elements.
Returns: It returns an array of all items in the specified collection or iterator.
Example 1:
println(collect( 1 : 2 : 13 ))
println(collect( 1 : 4 ))
println(collect( 1 : 10 ))
println(collect( 1 : 5 : 10 ))
|
Output:
[1, 3, 5, 7, 9, 11, 13]
[1, 2, 3, 4]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[1, 6]
Example 2:
println(collect(Int32, 1 : 2 : 5 ))
println(collect(Int64, 1 : 5 ))
println(collect(Float32, 1 : 2 : 5 ))
println(collect(Float64, 1 : 5 ))
|
Output:
Int32[1, 3, 5]
[1, 2, 3, 4, 5]
Float32[1.0, 3.0, 5.0]
[1.0, 2.0, 3.0, 4.0, 5.0]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...