Hi all,
I have a list in scala called l : List[AType] that I want to change to list[String].
This may sound like a very dirty, inefficient approach, but I'm not quite sure of the best way to do this. My code was:
var result = new Array[String]("a","b")
l foreach { case a => result = result :+ (a.toString().toUpperCase()); }
result toList
I'm not sure if this is where my mistake is, because it's not giving me anything, it's not even printing anything even if I put a print statement inside the loop.
So I decided to change this to a more imperative way:
for(i <- 0 to l.length) {
result.update(i, l(i).toString)
}
This time I see things that I want to see when printing inside the loop, but at the end the program crashed with an IndexOutOfBound error.
Is there any more efficient and better way to do this?
Thanks!