Scala Collections Overview

Scala collection framework is a set of very rich and user friendly collection classes. And functional capabilities of Scala makes these collections safe, easy to use, concise, fast and universal. Here in this post we’ll take an overview of Scala collection classes.

By definition, collections are the dynamic growing group of objects of the same type, which enables certain operation on that group of data using some easy to use methods.

If you are not able to digest above definition let’s make it simple.

Collection classes are,

  • Group of same type of objects, means this group can be list, set or map
  • Dynamically growing, means size of this group can grow with writing any specific code
  • Solve problems on group of data, means can solve problems like iteration, finding size of group, adding or removing elements in group, accessing elements in group (even on any position), transforming data (like mapping data to another value)
  • Easy to use methods, means it provides intuitive set of methods to perform above operation which are user friendly

I hope you get this. Let’s move on…..

Now, In Scala there is a package scala.collection which consist of all abstract classes and traits.

Scala collection abstract classes/traits
Scala collection abstract classes/traits (Source: http://docs.scala-lang.org/overviews/collections/overview.html)

All of above classes/traits have respective mutable as well as immutable implementation in scala.collection.mutable and scala.collection.immutable packages.

Mutable Collections

Scala Mutable Collections
Scala Mutable Collections (Source: http://docs.scala-lang.org/overviews/collections/overview.html)

Immutable Collections

Scala Immutable Collections
Scala Immutable Collections (Source: http://docs.scala-lang.org/overviews/collections/overview.html)

When you talk about collections; List, Set and Map are the core collection types which are widely used. Below are my posts which will explain you all of these collection types with relevant code examples,

References

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>