Scala Iterator toSet() method with example
Last Updated :
26 Jul, 2019
The toSet() method belongs to the concrete value member of the class Abstract Iterator. It is defined in the class IterableOnceOps.
Method Definition: def toSet[B >: A]: immutable.Set[B]
Return Type: It returns a set from the stated collection.
Example #1:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 5 , 6 , 8 , 9 )
val result = iter.toSet
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator()
val result = iter.toSet
println(result)
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...