Scala turn comma delimited string to Array - Stack Overflow
stackoverflow.com › questions › 19748986Nov 3, 2013 · Starting Scala 2.13, if you expect items that can't be cast, you might want to use String::toIntOption in order to safely cast these split String s to Option [Int] s and eliminate them with a flatMap: "1,100,53s,5000,4,5,5".split (',').flatMap (_.toIntOption).distinct // Array [Int] = Array (1, 100, 5000, 4, 5) Share Follow