Scala Stream head() method with example
Last Updated :
26 Jul, 2019
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:
object GfG
{
def main(args : Array[String])
{
val m 1 = Stream( 3 , 6 , 7 , 4 )
val result = m 1 .head
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val m 1 = Stream( 6 , 8 , 9 , 12 )
val result = m 1 .head
println(result)
}
}
|
Share your thoughts in the comments
Please Login to comment...