Skip navigation.

Plugable Groovy Maps and Lists

Idiomatic code for many languages with native lists and maps is full of them-- and the code is clearer for it. In most languages there are many uses for them but there is only one general purpose implementation. Performance and flexibility are both fixed. Groovy is different! You can use that great list and map syntax and API with any implementation.

By default, ArrayList and HashMap are used from the JDK. These are good general purpose choices, of course. To change this just declare your map or list with any valid implementation of the standard Java interfaces java.util.List or java.util.Map. Use the plain old Java/Groovy method declaration syntax like this:

def list = new LinkedList()

You can use any of the standard JDK implementations, one of the many open source implementations, or maybe your own custom implementation. You can put your data in a DBMS, put it in a file system, put it in the stack, on the heap, put in in primitives, put it in the toaster if you want. If you proud of it you can export it your website-- if your ashamed you can delete automatically. You can use a proxy to keep it sorted, keep it unique, keep it small, or keep it morally pure. There is even, I kid you not, a singleton map in the Apache Commons. http://Java-source.net keeps a list of collections libraries. Not all of them actually implement the standard List and Map interfaces but the Apache Commons collections do.