I'm using hazelcast IMap[String,Any] in my application. When printing the map it should be sorted by the keys.
Is there a nice way to sort the IMap by key (other than sort the keys locally and print by the sorted keys)?
由于IMap
扩展了常规java.util.Map
,您可以使用 a scala.collection.immutable.TreeMap
,它始终按键排序。
println(TreeMap() ++ imap)
这显然不是免费的,因为您IMap
每次想要打印它时都需要对其进行迭代和排序。