Thursday, 5 September 2013

Safely Get Tail of Array

Safely Get Tail of Array

I called tail on an Array, but saw a warning.
scala> val arr = Array(1,2)
arr: Array[Int] = Array(1, 2)
scala> arr tail
warning: there were 1 feature warning(s); re-run with -feature for details
res3: Array[Int] = Array(2)
Scaladocs for Array shows an UnsupportedOperationException [will be
thrown] if the mutable indexed sequence is empty.
Is there a safe, won't throw exception, way to get the tail of an array?

No comments:

Post a Comment