Search code examples
scala

Convert List[Any] to List[Int]


How can I convert

List(1, 2, "3")

to

List(1, 2, 3)

since List(1, 2, "3") is of type List[Any] and I can't use .toInt on Any.


Solution

  • That should be sufficient solution:

    l.map(_.toString.toInt)