package com.novoda.notils.string;

import java.util.Collection;
import java.util.Iterator;

public abstract class StringUtils {

    private final static String EMPTY_STRING = "";
    private final static String THREE_DOTS = "…";

    /**
     * Joins a Collection of typed objects using their toString method, separated by delimiter
     *
     * @param collection Collection of objects
     * @param delimiter  (optional) String to separate the items of the collection in the joined string - <code>null</code> is interpreted as empty string
     * @return the joined string
     */
    public static String join(Collection<?> collection, String delimiter) {

        if (collection == null || collection.isEmpty()) {
            return EMPTY_STRING;
        } else if (delimiter == null) {
            delimiter = EMPTY_STRING;
        }

        StringBuilder builder = new StringBuilder();
        Iterator<?> it = collection.iterator();

        while (it.hasNext()) {
            builder.append(it.next()).append(delimiter);
        }

        int length = builder.length();
        builder.delete(length - delimiter.length(), length);
        return builder.toString();
    }

    /**
     * Truncates the string provided if its length is more than the value provided, and replaces
     * the extra text by "…" ensuring that the resulting length of the string will be
     * as maximum as the param maximumLengthAllowed
     *
     * @param maximumLengthAllowed The maximum allowed length for the provided string
     * @param string The string that will be truncated if necessary
     * @return The original string if its length is less than maximumLengthAllowed,
     * or the string cropped and … appended at the end if it's length is more than maximumLengthAllowed
     */
    public static String truncateIfLengthMoreThan(final int maximumLengthAllowed, String string) {
        if (string.length() > maximumLengthAllowed) {
            return string.substring(0, maximumLengthAllowed - THREE_DOTS.length()).concat(THREE_DOTS);
        } else {
            return string;
        }
    }
}

@@ -2092,11 +2092,573 @@
  %7D%0A    %7D
+%0A%0A    /**%0A     * Create a String array from a generic Object array%0A     *%0A     * @param objects The array of objects to be converted to Strings%0A     * @return An String array in which every element is the String representation of an element from the input array%0A     */%0A    public static String%5B%5D toStringArray(Object%5B%5D objects) %7B%0A        int length = objects.length;%0A        String%5B%5D stringArray = new String%5Blength%5D;%0A        for (int i = 0; i %3C length; i++) %7B%0A            stringArray%5Bi%5D = String.valueOf(objects%5Bi%5D);%0A        %7D%0A        return stringArray;%0A    %7D
 %0A%7D%0A

Add toStringArray to StringUtils