Reputation: 11
Is there any difference between hashmap and listmap in terms of properties.
var listMap = ListMap("Rice"->"100","Wheat"->"50","Gram"->"500") // Creating listmap with elements
and
var hashMap2 = HashMap("A"->"Apple","B"->"Ball","C"->"Cat")
Upvotes: 1
Views: 1557
Reputation: 14825
Main difference: ListMap
maintains the order of elements while HashMap
doesn't.
In case of ListMap:
Entries are stored internally in reversed insertion order, which means the newest key is at the head of the list. Iteration order is always guaranteed.
In case of HashMap:
No guarantees on iteration order.
for more info:
ListMap https://www.scala-lang.org/api/current/scala/collection/immutable/ListMap.html
Upvotes: 3