【发布时间】:2018-10-01 09:22:00
【问题描述】:
我有这样的地图:
val myMap = Map(
testKey1 -> List(testValue1, testValue2, testValue3....),
testKey2 -> List(testValue4, testValue5, testValue6....),
testKey3 -> List(testValue7, testValue8, testValue9....)
)
我想做一些list值的精确匹配,得到map对应的key。
例如:我想检查 'testValue9' 是否在此 Map 中,然后我会得到键 'testKey3'。
我认为它可以通过这种方式解决,但我无法遍历列表的值来检查该值是否存在。 或者有人可以给我一些提示。
myMap foreach {
case (key, List(_)) => println( key )
case _ =>
}
【问题讨论】:
-
作为一般评论,对于此用例,Map 是一个相当糟糕的数据结构选择。
标签: scala