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集合中添加元素