3

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)?

4

1 回答 1

1

由于IMap扩展了常规java.util.Map,您可以使用 a scala.collection.immutable.TreeMap,它始终按键排序。

println(TreeMap() ++ imap)

这显然不是免费的,因为您IMap每次想要打印它时都需要对其进行迭代和排序。

于 2013-01-09T10:05:11.737 回答