How to create sorted map in scala (mutable/immutable)?
How to create sorted map in scala?
Asked Answered
scala.collection.immutable.SortedMap exists as of 2.8, but there's no mutable version. –
Limpid
Use a TreeMap
.
Indeed. It is immutable, so updates cost log(n) in space (i.e. garbage collector churn) as well as time. But there isn't a mutable implementation, so it's the best solution presently (which is to say, good for most things except very intensive usage). –
Chantal
There's always java.util.TreeMap which, although not as nice as Scala's maps, is probably exactly the behavior for which you're looking.
© 2022 - 2024 — McMap. All rights reserved.