How can I retrieve the first five elements from a list in Scala?
To access the first five elements in the list, you can use the take method. This method will return a new list containing the first n elements from the original list.
The sample code is as follows:
val list = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val firstFive = list.take(5)
println(firstFive)
The output is: List(1, 2, 3, 4, 5)