0

So this is my code:

import scala.collection.mutable.MutableList 

val list = MutableList[Any]()
val input = scala.io.StdIn.readLine("Please enter your list of values separated by a comma:").split(",")
val toList = for (e <- input if(!e.trim.isEmpty())) yield e.trim.toString
list += toList
println(list)

But when the "list" gets printed it doesn't show me the input seperated by commas, besides it prints the following:

MutableList([Ljava.lang.String;@d716361)

Why is that so?

1 Answer 1

3

Now your input is an Array which doesn't have pretty toString representation. Change your input to:

val input = scala.io.StdIn.readLine("Please enter your list of values separated by a comma:").split(",").toList
Sign up to request clarification or add additional context in comments.

3 Comments

Ah okay. So if I use the .split(",") operator it is putting my input into an array of Strings splitted by a comma? and therefore its not only one string but an array containing strings?
@ArmaGeddon, exactly!
ah okay thats explains a lot...But i thought that too because it was always telling me that it has found an Array(String) :)

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.