我做了“mkString”,但仍然无法打印字符串列表。带输入线:
9002194187,2644,54,100,3,4,2,5
我得到以下输出:
Line: 9002194187,2644,54,100,3,4,2,5
StrArr: 9002194187,2644,54,100,3,4,2,5
Lst: [Ljava.lang.String;@223d2e6c
Lst again: List([Ljava.lang.String;@223d2e6c)
Lst1: [Ljava.lang.String;@223d2e6c
Result: foo
从下面的代码:
def mkRecord(line: String) : String = {
val klass = "foo"
val strArr = line.split(",") // convert string to array of strings
println("Line: "+line)
println("StrArr: "+strArr.mkString(","))
val lst = List(strArr)
println("Lst: "+lst.mkString(" - "))
println("Lst again: "+lst)
val lst1 = lst.tail ++ List(klass) // attribute list except for the first one, plus new klass attribute
println("Lst1: "+lst.mkString(" , "))
val result = lst1.mkString(",") // attribute string
println("Result: "+ result)
return result
}
请帮忙。我完全失去了(