Scala Set init() method with example
The init() method is utilized to find all the elements of the set except the last one.
Method Definition: def init: Set[A]
Return Type: It returns all the elements of the set except the last one.
Example #1:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( 1 , 2 , 3 , 4 , 5 )
val result = s 1 .init
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( 16 , 22 , 3 , 41 , 51 )
val result = s 1 .init
println(result)
}
}
|
Output:
Set(41, 22, 3, 16)
Last Updated :
18 Oct, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...