Reputation: 1543
how can I convert a Scala set of strings
val s = Set("1","2","3")
to a set of long?
Set(1, 2, 3)
Thanks!
Upvotes: 0
Views: 495
Reputation: 22449
Adding long
value check:
import scala.util.{Try, Success, Failure}
val s = Set("1", "2", "3", "x")
s.map( x => Try(x.toLong) match {
case Success(e) => e
case Failure(_) => -999L
} )
res1: scala.collection.immutable.Set[Long] = Set(1, 2, 3, -999)
Upvotes: 2