cast LinkedHashMap to HashMap in groovy

user140736 picture user140736 · Sep 23, 2010 · Viewed 18.4k times · Source

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.

Answer

Colin Hebert picture Colin Hebert · Sep 23, 2010

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


Resources :