Reputation: 837
I use SortedMap
for storing ordered elements:
val map = SortedMap("Kim" -> 90, "Steve" -> 22, "Alex" -> 12)
My questions are:
SortedMap
?SortedMap
same to Red black tree
?SortedMap
in Java is an interface, why in Scala it can be instantiated?Upvotes: 1
Views: 106
Reputation: 23329
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.
Upvotes: 3