@deprecated(“在scala-collection-contrib模块中使用scala.collection.mutable.MultiDict”,"2.13.0")
用法:
trait MultiMap[K, V] extends Map[K, Set[V]]
具有分配给键的多个值的可变映射的特征。
此类通常用作 mixin。它将映射K
到Set[V]
对象的映射转换为映射K
到V
对象的多映射。
例子:
// first import all necessary types from package `collection.mutable` import collection.mutable.{ HashMap, MultiMap, Set } // to create a `MultiMap` the easiest way is to mixin it into a normal // `Map` instance val mm = new HashMap[Int, Set[String]] with MultiMap[Int, String] // to add key-value pairs to a multimap it is important to use // the method `addBinding` because standard methods like `+` will // overwrite the complete key-value pair instead of adding the // value to the existing key mm.addBinding(1, "a") mm.addBinding(2, "b") mm.addBinding(1, "c") // mm now contains `Map(2 -> Set(b), 1 -> Set(c, a))` // to check if the multimap contains a value there is method // `entryExists`, which allows to traverse the including set mm.entryExists(1, _ == "a") == true mm.entryExists(1, _ == "b") == false mm.entryExists(2, _ == "b") == true // to remove a previous added value there is the method `removeBinding` mm.removeBinding(1, "a") mm.entryExists(1, _ == "a") == false
已弃用
源码:
- MultiMap.scala
相关用法
- Scala mutable.PriorityQueue用法及代码示例
- Scala mutable SortedSet contains()用法及代码示例
- Scala mutable SortedSet equals()用法及代码示例
- Scala mutable SortedSet subsetOf()用法及代码示例
- Scala mutable SortedSet drop()用法及代码示例
- Scala mutable SortedSet diff()用法及代码示例
- Scala mutable SortedSet apply()用法及代码示例
- Scala mutable SortedSet dropRight()用法及代码示例
- Scala math.Ordering用法及代码示例
- Scala map isDefinedAt()用法及代码示例
- Scala map contains()用法及代码示例
- Scala matching.Regex用法及代码示例
- Scala map()用法及代码示例
- Scala math.Ordered用法及代码示例
- Scala Tabulate.sliding用法及代码示例
- Scala ArrayBuffer.inits用法及代码示例
- Scala long.BitwiseOr用法及代码示例
- Scala StringBuilder.partitionMap用法及代码示例
- Scala List distinct()用法及代码示例
- Scala DefaultMap.sizeIs用法及代码示例
- Scala StrictOptimizedIterableOps.sliding用法及代码示例
- Scala Searching.SearchResult用法及代码示例
- Scala ::.collectFirst用法及代码示例
- Scala TreeSet diff()用法及代码示例
- Scala Char getClass()用法及代码示例
注:本文由纯净天空筛选整理自scala-lang.org大神的英文原创作品 mutable.MultiMap。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。