Java collections – Are there alternatives?

The built-in collections for Java have good performance and are nice to use – especially with the new for-loop pattern.

But are there alternatives? And if so, why should I use them? (Please use the comment functionality ;-) )

The following collection implementations I found on the web:

There are also some older projects, where the development seems to be abandoned:

If you need real big data in memory you should consider a lightweight database (or a real one??) like neodatis, derby or something really interesting: HBase from the hadoop project (Apache/Yahoo!).

10 Responses to “Java collections – Are there alternatives?”


  1. 1 mafr 3 September, 2009 at 16:36

    As long as you’re happy, there’s no need to use anything else. The JDK’s collections framework has been optimized and it keeps improving from release to release. The idea behind GNU Trove was to provide optimized drop-in replacements for the standard collections classes. In my experience, starting from JDK-1.5, Trove is slower and it also lacks Generics support. But you should measure performance for yourself, maybe there are use cases where Trove is still faster.

    Then there’s a number of data structures that the JDK doesn’t offer, for example MultiMap/Bag data structures. Google Collections and Commons Collections offer quite a few additional data structures.

    Commons collections don’t support Generics and sometimes they violate the JDK’s interface contracts. That’s a no-go for me.

    Google Collections are high-quality and intended to complement the JDK’s collection classes. They always follow the JDK interface contract. You can safely use them if the JDK doesn’t offer what you need.

    I don’t know about the other ones. In general, I don’t trust them because it’s unlikely that they went through the same QA process that the JDK classes did.

    • 2 karussell 3 September, 2009 at 17:07

      Thanks for sharing!

      2 minutes ago I replaced all HashMap’s and LinkedHashMap’s in my TimeFinder application with FastMap (javolution) and it is faster :-)

      I had 16 samples for the complex algorithm: sometimes the improvement is only a bit but the most times it is a lot … nice … without any effort

  2. 3 mafr 3 September, 2009 at 17:28

    Did you try ConcurrentHashMap from the JDK yet? I know it’s counter-intuitive, but I heard that it performs better in some cases than HashMap.

    In case you test it, please let me know how it turns out :)

  3. 4 karussell 3 September, 2009 at 21:15

    Thanks for the hint. And indeed the ConcurrentHashMap is often faster than the HashMap, but in my case it was not faster than FastMap. But please always test for yourself :-)
    The algorithm uses more often Map.get() than e.g. put() in the critical places …

    Unless I won’t detect performance problems I will choose FastMap, because to test performance the predictability of iteration is very important. HashMap iterates “non-deterministic” – I.e. if you put some keys A,B,C the iteration over the elements will depend on execution (randomly!) and not on insertation order like it is the case for FastMap.

  4. 5 Hezaurus 4 September, 2009 at 14:14

    I wouldn’t say that fastutil is abandoned. It’s just that it’s ‘finished’. I’ve been using it for seven? years already and I have to say that it’s the most bug free library that I’ve used.

    I’m using fastutil classes as a basis for custom object cache. They are both faster and less memory hogs than the built in collections in jdk.

    P.S.
    I’m pretty sure that the fastutil library gets updated as soon as generics move to the next level (if they ever do).

  5. 6 karussell 4 September, 2009 at 15:11

    Thanks for this information! I updated the post accordingly (I meant the development seems to be abandoned).

  6. 7 Toni Epple 5 September, 2009 at 07:09

    Nice list. My favorite is Trove! It’s my magic bullet for fighting memory problems.
    –Toni

  7. 9 karussell 5 September, 2009 at 09:56

    > Functional Java http://functionaljava.org/

    Does it re-implement some of the collections? Or does it only wrap the existing?

  8. 10 dibblego 5 September, 2009 at 10:57

    Functional Java certainly does. It’s like Google Collections, except a lot more practical.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s





Follow

Get every new post delivered to your Inbox.

Join 191 other followers