Skip to content
Related Articles

Related Articles

Getting first element of an array in Julia – first() Method
  • Last Updated : 26 Mar, 2020

The first() is an inbuilt function in julia which is used to return the first element of the specified iterable collection.

Syntax: first(coll)

Parameters:

  • coll: Specified iterable collection.

Returns: It returns the first element of the specified iterable collection.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Julia program to illustrate 
# the use of first() method
   
# Getting the first element of 
# the specified iterable collection
# or 1D array
println(first(1:2:3))
println(first(5:10))
println(first([3, 5, 7, 9]))
println(first([2, 4, 6, 8]))

chevron_right


Output:

1
5
3
2

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Julia program to illustrate 
# the use of first() method
   
# Getting the first element of 
# the specified 2D and 3D array
println(first([3 5; 7 9]))
println(first(["a" "b"; "c" "d"]))
println(first(cat([1 2; 3 4], [5 6; 7 8], 
                  [2 2; 3 4], dims = 3)))
println(first(cat(["a" "b"; "c" "d"], 
                  ["e" "f"; "g" "h"], 
                  ["i" "j"; "k" "l"], dims = 3)))

chevron_right


Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :