In Python, you can get a sublist from a certain starting index to the end using x[i:]
, for example if x = [1, 2, 3, 4], x[1:]
would give you [2, 3, 4]
. I was wondering what is the equivalent way to do this in Scala.
Asked
Active
Viewed 114 times
-1

MetallicPriest
- 29,191
- 52
- 200
- 356
2 Answers
2
Use drop
for this case:
x.drop(1)
For the particular case of 1, we usually use x.tail
instead.

sjrd
- 21,805
- 2
- 61
- 91
-
3There's an important difference between `.drop(1)` and `tail`: `tail` throws an exception on an empty collection. – Travis Brown Nov 15 '14 at 18:05
-
Good point. I had overlooked that. – sjrd Nov 15 '14 at 18:31
1
It's called drop
and you use it like xs.drop(i)
.