val files = new File("data").list()
val filtered = files.filter(name => name.contains("txn"))
val masterList = new ListBuffer[String]
for (file <- filtered) {
val lines = Source.fromFile(new File("data\\" + file), "UTF-16").getLines
val cleaned = lines.filter(!masterList.contains(_))
println("*" + cleaned.length)
cleaned.foreach(println(_))
println("**" + cleaned.length)
cleaned.foreach(masterList.append(_))
}
從代碼的輸出如下爲什麼我的Scala列表在下面的代碼中消失?
*175
**0
我不明白爲什麼我的列表中消失
哇。這種行爲讓我無法理解。從來沒有想過,對'長度'的無害調用實際上會破壞整個事情! – lolski
@ lolski我會說*消耗*整個事情 –
這就是更好的詞。 omnomnomnomm – lolski