scala集合中添加元素
清单 (List)
A list is a linear data structure. It is a collection of elements of the same data types.
列表是线性数据结构。 它是相同数据类型的元素的集合。
Scala libraries have many functions to support the functioning of lists. Methods like isempty, head, tail, etc provide basic operations on list elements.
Scala库具有许多功能来支持列表的功能。 像isempty , head , tail等方法提供对列表元素的基本操作。
获取列表的第一个元素 (Getting first element of the list)
You can access the first element of the list in Scala using the head method form the list.
您可以使用head方法从Scala访问Scala中列表的第一个元素。
Program:
程序:
object MyObject{
def main(args:Array[String]) {
val myBikes = List("ThunderBird 350", "Yamaha R3", "BMW S1000R", "Iron 883")
println("list of my Bikes : " + myBikes)
println("First Bike from the list is: " + myBikes.head)
}
}
Output
输出量
list of my Bikes : List(ThunderBird 350, Yamaha R3, BMW S1000R, Iron 883)
First Bike from the list is: ThunderBird 350
翻译自: https://www.includehelp.com/scala/how-to-get-the-first-element-of-the-list-in-scala.aspx
scala集合中添加元素