scala集合中添加元素_如何在Scala中获得列表的第一个元素?
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集合中添加元素
總結
以上是生活随笔為你收集整理的scala集合中添加元素_如何在Scala中获得列表的第一个元素?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python凯撒密码实现_密码:凯撒密码
- 下一篇: excel添加列下拉框票价_excel表