arrays - Best way to change list type in scala -
I have a list named l: list [ATP] that I want to change the list to [string] .
This may look like a very dirty, incompetent approach, but I'm not the best way to make sure. My code was:
var results = new array [string] ("a", "b") l foreach {case a => Result = result: + (a.toString (.) ToUpperCase ()); } I do not know that this is my fault, because it is not giving me anything, even if I put a print statement inside the loop, even then nothing is printing anything. So I decided to change it in a more compulsive way:
for (i <-0 to l.length) {result.update (i , L (I) .toString)}
This time when I want to see it while printing inside the loop, but in the end the program crashed with an index outbound error
< P> Thanks!
"text">
Take a look at the map function. For example,
Scala> List ("Some", "Wire") Map (_ ToUpperCase) res2: list [java.lang.String] = list (some, STRINGS)
or
scala> List ("Some", "Wire") Map (_ length) res0: list [int] = list (4, 7)
Comments
Post a Comment