1

I use SortedMap for storing ordered elements:

val map = SortedMap("Kim" -> 90, "Steve" -> 22, "Alex" -> 12)

My questions are:

  1. What is the implementation stand under SortedMap?
  2. Does SortedMap same to Red black tree?
  3. SortedMap in Java is an interface, why in Scala it can be instantiated?
evan.oman
  • 5,922
  • 22
  • 43
pacman
  • 797
  • 10
  • 28

1 Answers1

3

The default implantation of SortedMap in Scala is a TreeMap which is an immutable Red-Black tree. Not to be confused with Java's java.util.TreeMap which is mutable.

Why SortedMap in Scala can be instantiated? It can't, it's a trait but the SortedMap companion object gives you the flexibility to initialise the object this way.

Sleiman Jneidi
  • 22,907
  • 14
  • 56
  • 77