Open In App

Getting last index of a collection in Julia – lastindex() Methods

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

The lastindex() is an inbuilt function in julia which is used to return the last index of the specified collection. If a dimension d is given, return the last index of collection along dimension d.

Syntax:
lastindex(collection)
or
lastindex(collection, d)

Parameters:

  • collection: Specified collection.
  • b: Specified dimension.

Returns: It returns the last index of the specified collection. If a dimension d is given, return the last index of collection along dimension d.

Example 1:




# Julia program to illustrate 
# the use of lastindex() method
   
# Getting the last index of the specified collection.
println(lastindex(0))
println(lastindex([1, 2, 3]))
println(lastindex([2 4; 5 6]))
println(lastindex([3; 5; 7; 9]))


Output:

Example 2:




# Julia program to illustrate 
# the use of lastindex() method
   
# Getting the last index of the specified 
# collection. If a dimension d is given, 
# return the last index of collection 
# along dimension d.
println(lastindex(rand(1, 2, 3, 4), 1))
println(lastindex(rand(1, 2, 3, 4), 2))
println(lastindex([1, 2, 3], 2))
println(lastindex([2 4; 6 8], 2))
println(lastindex([2; 4; 6; 8], 2))
println(lastindex(cat([1 2; 3 4], [5 6; 7 8], [2 2; 3 4], dims = 3);))


Output:



Last Updated : 26 Mar, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads