ScalaでLinkedHashMapの要素の順序を逆にするエレガントな方法はありますか?ScalaでLinkedHashMap要素の順序を逆にする方法
は例えば、私が持っているようなのLinkedHashMap [整数、文字列]:
[1, "one"]
[2, "two"]
[3, "three"]
何のようなのLinkedHashMap [整数、文字列]を取得するための最良の方法である:
[3, "three"]
[2, "two"]
[1, "one"]
ScalaでLinkedHashMapの要素の順序を逆にするエレガントな方法はありますか?ScalaでLinkedHashMap要素の順序を逆にする方法
は例えば、私が持っているようなのLinkedHashMap [整数、文字列]:
[1, "one"]
[2, "two"]
[3, "three"]
何のようなのLinkedHashMap [整数、文字列]を取得するための最良の方法である:
[3, "three"]
[2, "two"]
[1, "one"]
import scala.collection.mutable.LinkedHashMap
val linked = LinkedHashMap(1 -> "one", 2 -> "two", 3 -> "three")
val reversed = LinkedHashMap(linked.toSeq.reverse: _*)
// reversed: scala.collection.mutable.LinkedHashMap[Int, String] = Map(3 -> three, 2 -> two, 1 -> one)
ありがとうございます。自分のために '_ *'を発見しました:) – Strig