Useful Apache Commons utilities

So I’ve been on a number of projects now at Intelliware and on most of them (if not all) have used Apache Commons utilities. I haven’t taken the time to look at them in depth to see exactly what they offer (it’s on my to do list), so every once in a while I’ll have one of those “hey, I didn’t know commons did that for you!” moments. Here’s my latest one…

Dion and I had an simple object array of phone number objects of say 5 objects. We just wanted the first 3 elements in the array. My first instinct was just loop over the phone number array and grab the first 3 elements which I’d add to some other array. Then Dion pointed out this handy commons utility…

public PhoneNumber[] getFirstThreePhoneNumbers() {
    ...
    return (PhoneNumber[]) ArrayUtils.subarray(phoneNumbers, 0, 3);
}

Sweet! one line to replace an entire loop. So after we committed this, I asked myself: I wonder how many times I’ve rewritten some basic collection utility code that commons already does for me?
What are the most important Intelliware approved commons utilities that I should familiarize myself with?

Hence this post. So what are some of your favourite or frequently used commons utilities? It would be great to have a i-proving page or section where I can have a quick peek at every once in a while just to make sure I don’t re-invent the wheel every time I write some utility code. If such an page exists, please post a link. If not, let’s start one!

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply