Scala List init() method with example
Last Updated :
29 Jul, 2019
The init() method is utilized to find all the elements of the list except the last one.
Method Definition: def init: List[A]
Return Type: It returns all the elements of the list except the last one.
Example #1:
object GfG
{
def main(args : Array[String])
{
val m 1 = List( 3 , 6 , 2 , 9 , 21 )
val result = m 1 .init
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val m 1 = List( 3 )
val result = m 1 .init
println(result)
}
}
|
Share your thoughts in the comments
Please Login to comment...