如何使用 Scala 打印列表中的第一个元素?
例如在 Python 中,我可以只写:
>>>l = [1,2,3,4]
>>>one = l[0]
>>>print one
我怎么能在 Scala 上做到这一点
谢谢。
最佳答案
正如日浦所说,或者像这样:
object ListDemo extends App {
val lst = List(1, 2, 3)
println(lst(0)) // Prints specific value. In this case 1.
// Number at 0 position.
println(lst(1)) // Prints 2.
println(lst(2)) // Prints 3.
}
关于scala - 使用Scala打印列表中的第一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18933405/