Scala Map 与 HashMap
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31685236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Scala Map vs HashMap
提问by jstnchng
Is there a difference between a Scala Mapand a HashMap? I am using the scala.collection.immutable.HashMap.
ScalaMap和之间有区别HashMap吗?我正在使用scala.collection.immutable.HashMap.
回答by johanandren
scala.collection.immutable.Mapis the interface for immutable maps while scala.collection.immutable.HashMapis a concrete implementation.
scala.collection.immutable.Map是不可变映射的接口,而scala.collection.immutable.HashMap是具体实现。
Creating with Map()or Map.emptygives a special empty singleton map, with Map(a -> b)with up to 4 pairs yields specialized classes for such small maps, and 5 and upwards gives you scala.collection.immutable.HashMap
创建Map()或Map.empty提供一个特殊的空单例映射,Map(a -> b)最多 4 对生成用于此类小映射的专用类,5 及以上为您提供scala.collection.immutable.HashMap

