Hierarchy of collections in Scala
The hierarchical structure of Scala collections is easy to understand. When you start working with collections, it becomes easy to use any method that is already defined in a super trait, and for specific implementations you can define your own versions. The structure has been classified in three distinct categories, that is:Â root
,mutable
, and immutable
. We've discussed the differences between them. To strengthen our discussion, let's take a look at the hierarchy of root
package collections:
Root collection hierarchy
The preceding hierarchy is for collections in the root
package. All the collections inherited from the super trait are called Traversable. Traversable defines the foreach
abstract method, along with other helper methods that can relate to any collection in the hierarchy. So, it's clear that every other collection needs to give a definition of the foreach
 method in its implementation. We'll have a look at Traversable trait in the next few topics...