Pranav Kapoor
Pranav Kapoor

Reputation: 1281

Extract numbers from String Array in Scala

I'm new to Scala and unsure of how to achieve the following

I have the String

val output = "6055039\n3000457596\n3000456748\n180013\n"

I want to extract the numbers separated by \n and store them in an Array

Upvotes: 0

Views: 178

Answers (1)

holothuroid
holothuroid

Reputation: 381

output.split("\n").map(_.toInt)

Or only

output.split("\n")

if you want to keep the numbers in String format. Note that .toInt throws. You might want to wrap it accordingly.

Upvotes: 1

Related Questions