drewish


Reason #902,423 why Java sucks   12 February 2008

I’ve grown increasingly annoyed at Java over the years. I’ve taken to describing the language designer’s philosophy as “If there’s two ways of doing anything, pick the one that involves more typing”.

All I want to do in take an array of numbers and convert it into a comma separated list, e.g. 1,2,3,4. Most modern languages make this easy:

So how do you do it in Java? Well there’s no built in method so you end up getting to write your own:

public static String join(String[] a, String separator) {
    StringBuffer result = new StringBuffer();
    if (a.length > 0) {
        result.append(a[0]);
        for (int i=1; i<a.length; i++) {
            result.append(separator);
            result.append(a[i]);
        }
    }
    return result.toString();
}

Maybe sometime around Java 9 they’ll get around to adding it…

← Back to the top