Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between HashMap and MutableMap in Kotlin

Tags:

kotlin

Lots of documents have indicated the difference between Map and MutableMap in Kotlin, however, I can't seem to find the difference between HashMap and MutableMap. Can they be used interchangeably? Are there any differences in the implementation level of this 2 data structure? Can someone please elaborate.

And as people have pointed out that MutableMap is an interface. Then when I use a map, what's the difference between using mutableMapOf and hashMapOf?

Thanks.

like image 692
ljzhanglc Avatar asked Jul 27 '18 18:07

ljzhanglc


1 Answers

HashMap is an implementation of the interface MutableMap. From the former link:

Hash table based implementation of the MutableMap interface.

There can be other implementations, like LinkedHashMap. You can read the documentation at these links to discover which behaviors are common to all MutableMap implementations, and which are specific to HashMap or LinkedHashMap.

like image 167
Joe Sewell Avatar answered Oct 03 '22 15:10

Joe Sewell