Joined September 2013
·

Oliver Weiler

Software Developer at predic8 GmbH
·
Germany
·
·

Posted to StringBuilderUtil over 1 year ago

Java 8 also has a static join() method which is much more powerful than your append method (you can e.g. define a delimiter for joining).

But if you're stuck with Java < 8 your implementation is quite nice.

To avoid code duplication, I would suggest that insert calls append with the array reversed, something like:

public static StringBuilder insert(Object... obj) {
    List<Object> l = new ArrayList<>(Arrays.asList(obj));
    Collections.reverse(l);

    return append(l.toArray());
}

Thanks for this tip, just what I was looking for. Sadly this doesn't seem to be part of the official documentation.

Achievements
28 Karma
0 Total ProTip Views
Interests & Skills