Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Java Collections library do you recommend? [closed]

I've inherited a team and a (Java) code base.

The code base makes use of a lot of explicit for each loops. I'd like to replace those (edit: in future code) with something like Commons Collections Transformers and Predicates and its collect and transform methods.

However, Commons Collection isn't generic. The rest of my code base, whatever else it lacks, is, and I don't want to introduce a lot of casting.

So I'm looking at the Commons-Collections with Generics (http://sourceforge.net/projects/collections/) and at Guava (formerly Google Collections) (http://code.google.com/p/guava-libraries/).

Question one: is either or both of those libraries Generally Recognized As Safe for production use? Do you use either in production?

Question two: of the two, which do you recommend? Answers from anyone who has used either are great, answers from anyone who has used both even better!

Finally, my team includes a mix of contractors who are mid- to senior-level, and employees who are mid- and junior-level in Java (edit: but with multi-year experience in non-OO programming) . So I don't want to introduce more than one collections library, and I do want one that won't be too hard for any of my team to use.

Thanks!

Edit: I want to replace explicit loops because the amount of boilerplate obscures and overwhelms the actual business code. I've got nested loops calling functions with nested loops, all to do things that are one-liners. With the proper introduction and training, I feel my team will find a Collections/Transformer/Predicate approach cleaner, clearer, faster to write, and easier to read.

like image 546
tpdi Avatar asked Oct 13 '10 03:10

tpdi


People also ask

Which collection should I use Java?

The best general purpose or 'primary' implementations are likely ArrayList , LinkedHashMap , and LinkedHashSet . Their overall performance is better, and you should use them unless you need a special feature provided by another implementation. That special feature is usually ordering or sorting.

Is Java collections a framework or library?

The Java collections framework is a set of classes and interfaces that implement commonly reusable collection data structures.

What is collections in Java with examples?

The Java collections framework provides a set of interfaces and classes to implement various data structures and algorithms. For example, the LinkedList class of the collections framework provides the implementation of the doubly-linked list data structure.


3 Answers

I use Google collections in production and have never had a problem. Makes you wish java had function pointers, but he design is well thought out. Even he little things like Lists.newArrayList become the.standard way to new up a list.

like image 108
Nathan Feger Avatar answered Oct 03 '22 22:10

Nathan Feger


It seems that you are not looking for a Collection library, but rather a library for working with existing collections in a functionnal way.

I wrote such a library myself, but it is not open source (it is only used internally in my company), and it may not be the best designed one.

A library with the same goal seems promising : lambdaj. I haven't used it myself, but I think I wouldn't have written my library if I was aware of the existence of lambdaj, at that time.

like image 32
barjak Avatar answered Oct 03 '22 21:10

barjak


I suggest to give a look at lambdaj either. Here you can find an overview of the main features: http://code.google.com/p/lambdaj/wiki/LambdajFeatures

like image 39
Mario Fusco Avatar answered Oct 03 '22 22:10

Mario Fusco