2016-12-18 96 views
-1

我有3个相同长度的ListBuffers。found String,必需(字符串,字符串,字符串,诠释):元组斯卡拉

devicenamelist:ListBuffer [字符串]

datelist:ListBuffer [字符串]

wordcountssortedlistbuf [(字符串,整数)

现在我需要将它们转换格式

ListBuffer(String,String,String,Int)

我试着做以下

var sortedrecords=scala.collection.mutable.ListBuffer[(String,String,String,Int)]() 

for(i <- 0 to devicenamelist.length) 
{ 

sortedrecords+=(devicenamelist(i),datelist(i),wordcountssortedlistbuf(i)._1,wordcountssortedlistbuf(i)._2) 

} 

它给了我错误如下

[错误]找到字符串

必需(字符串,字符串,字符串,整数)

列表如何在顶部g附加操作只有一个字符串时,我的意图是创建(字符串,字符串,字符串,诠释)。我错过了什么吗?

感谢

回答

4

你缺少一对括号中的+=线,但是,请不要做,它伤害了我的眼睛看到别人写的Scala这样的事情。

尝试这样的事情,而不是:

val sortedrecords = devicenamelist.zip(datelist).zip(wordcountssortedlistbuf) 
.map { case ((devicename, date), (word, count)) => 
    (devicename, date, word, count) 
} 
+0

除了在元组运营商 - http://stackoverflow.com/a/13790933/409976 –

+0

@KevinMeredith它不是元组运营商伤了我的眼睛在OP的代码就像一个可变缓冲区被一个命令循环所填充一样。但是,元组操作符,过度特定的键入和对列表的索引访问也不能帮助... – Dima