Convert List[Any] to List[Int]
That should be sufficient solution:
l.map(_.toString.toInt)
Starting Scala 2.13
and the introduction of String#toIntOption
, we can make @liosedhel's answer a bit safer if needs be:
// val l: List[Any] = List(1, 2, "3")
l.flatMap(_.toString.toIntOption)
// List[Int] = List(1, 2, 3)