0

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

1
  • output.split("\n").map(_.toInt) But this isn't really a good question for SO. Please read this page for future reference: stackoverflow.com/help/how-to-ask Commented Jul 21, 2017 at 10:50

1 Answer 1

1
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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, I ended up using toLong as I have Long numbers as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.