How to create sorted map in scala?
Asked Answered
S

2

5

How to create sorted map in scala (mutable/immutable)?

Sydneysydnor answered 19/4, 2010 at 8:48 Comment(1)
scala.collection.immutable.SortedMap exists as of 2.8, but there's no mutable version.Limpid
U
9

Use a TreeMap.

Unaneled answered 19/4, 2010 at 8:49 Comment(1)
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
P
0

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.

Pronghorn answered 27/8, 2012 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.