Scala Stream head() method with example
The head() method is utilized to display the first element of the stream stated.
Method Definition: def head: A
Return Type: It returns the first element of the stated Stream.
Example #1:
// Scala program of head() // method // Creating object object GfG { // Main method def main(args : Array[String]) { // Creating a Stream val m 1 = Stream( 3 , 6 , 7 , 4 ) // Applying head method val result = m 1 .head // Displays output println(result) } } |
chevron_right
filter_none
Output:
3
Example #2:
// Scala program of head() // method // Creating object object GfG { // Main method def main(args : Array[String]) { // Creating a Stream val m 1 = Stream( 6 , 8 , 9 , 12 ) // Applying head method val result = m 1 .head // Displays output println(result) } } |
chevron_right
filter_none
Output:
6
Recommended Posts:
- Scala Set head() method with example
- Scala Stack head() method with example
- Scala TreeSet head() method with example
- Scala Queue head() method with example
- Scala SortedSet head() method with example
- Scala Stream takeRight() method with example
- Scala Stream
- Program to convert Java Set to Stream in Scala
- Program to convert Java list to Stream in Scala
- Scala Set contains() method with example
- Scala Set sum() method with example
- Scala Set min() method with example
- Scala Set max() method with example
- Scala Map last() method with example
- Scala Int abs() 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 contribute@geeksforgeeks.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.