Monday, March 22, 2010

StringBuffers that exist within a method

This won't be the biggest performance hit of all time, but no one seems to use a Vector when an ArrayList is sufficient. StringBuffer was released before StringBuilder, and old habits die hard.
public static String concat(Iterable iterable)
{
    StringBuffer buffer = new StringBuffer();
    for (String string : iterable)
    {
        buffer.append(string);
    }
    return buffer.toString();
}

No comments:

Post a Comment