In Scala, the first and last element of an array can be obtained using the head and last methods respectively. Here's an example:
val nums = Array(1, 2, 3, 4, 5)
// To get the first element
val first = nums.head
println(first) // Output: 1
// To get the last element
val last = nums.last
println(last) // Output: 5
In the above example, we have an array nums containing five elements. To get the first element, we use the head method. Similarly, to get the last element, we use the last method. Both methods return the corresponding element of the array.