Scala Map和HashMap [英] Scala Map vs HashMap
问题描述
Scala Map
和 HashMap
之间有区别吗?我使用 scala.collection.immutable.HashMap
。
Is there a difference between a Scala Map
and a HashMap
? I am using the scala.collection.immutable.HashMap
.
推荐答案
scala.collection.immutable.Map
是不可变地图的接口, scala.collection.immutable.HashMap
是一个具体
scala.collection.immutable.Map
is the interface for immutable maps while scala.collection.immutable.HashMap
is a concrete implementation.
使用 Map()
或创建Map.empty
给出一个特殊的空单例映射,用 Map(a - > b)
和多达位置对产生这种小映射的专用类, code> scala.collection.immutable.HashMap
Creating with Map()
or Map.empty
gives a special empty singleton map, with Map(a -> b)
with up to positions pairs yields specialized classes for such small maps and 5 and upwards gives you scala.collection.immutable.HashMap
这篇关于Scala Map和HashMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!