The toList() method belongs to the concrete value members of the AbstractIterable class and is defined in the TraversableOnce and GenTraversableOnce classes. It converts a traversable or iterator to a list but it doesn’t terminates for infinite-sized collections.
- Method Definition:
def toList: List[A]
- Return Type:
It returns a list from the stated traversable or an iterator.>/li>
List(8, 9, 10, 11)
Therefore, a List is generated from an iterator.
Therefore, an empty List is generated from an empty-iterator.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.