Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cast LinkedHashMap to HashMap in groovy

How do I convert LinkedHashMap to java.util.HashMap in groovy?

When I create something like this in groovy, it automatically creates a LinkedHashMap even when I declare it like HashMap h = .... or def HashMap h = ...

I tried doing:

HashMap h = ["key1":["val1", "val2"], "key2":["val3"]]

and

def HashMap h = ["key1":["val1", "val2"], "key2":["val3"]]

h.getClass().getName() still comes back with LinkedHashMap.

like image 666
user140736 Avatar asked Sep 23 '10 17:09

user140736


1 Answers

LinkedHashMap is a subclass of HashMap so you can use it as a HashMap.


Resources :

  • javadoc - LinkedHashMap
like image 166
Colin Hebert Avatar answered Sep 23 '22 11:09

Colin Hebert