How to find the last element of a list in Scala?
belongs to collection: Scala List Programs
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
belongs to collection: Scala List Programs
total answers (1)
Accessing the last element using the length of the list
We will use the index of the list to find the element. For this, we will find the length of the list and use (length-1) as index to access the last element.
Syntax:
Example to find the last element using the length of the list
Output:
Accessing the last element using the length of the list
To find the last element of the array, we will use the last function.
Syntax:
Example to find the last element using the last function
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer