In Scala, list is defined under
scala.collection.immutable package. A list is a collection of same type elements which contains immutable data. Let’s see how to get the first element of given List in Scala.
List in Scala contains many suitable methods to perform simple operations like head(), tail(), isEmpty(). Coming to list, head() method is used to get the heead/top element of the list.
below are examples to get first element of list.
The head of the list is: Geeks
List(10, 11, 12, 13, 14, 15, 16, 17, 18) First element is: 10
- How to skip only first element of List in Scala
- Find the last element of a list in scala
- Scala Map get() method with example
- How to get all the keys from a Scala map
- How to get all the values from a Scala map
- Scala SortedMap get() method with example
- Scala Mutable SortedMap get() method with example
- Scala Tutorial – Learn Scala with Step By Step Guide
- Program to convert Java list to an iterator in Scala
- Scala List isEmpty Operation with example
- How to print a list in Scala
- How to reverse a list in scala
- Scala List take() method with example
- Scala List splitAt() method with example
- Scala List drop() method with example
- Scala List takeWhile() method with example
- Scala List takeRight() method with example
- Scala List sum() method with example
- Scala List size() method with example
- Scala List product() method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.