我在 scala 中有一个元组
val captainStuff = ("One", "Two", "Three", "Four", "Five")
我如何遍历 for 循环?遍历列表和 map 很容易。但是如何循环元组。
谢谢!!
最佳答案
您可以将其转换为迭代器,例如:
val captainStuff = ("One", "Two", "Three", "Four", "Five")
captainStuff.productIterator.foreach(x => {
println(x)
})
顺便说一句,这个问题是重复的:
关于scala - 如何在scala中循环遍历元组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44701879/