Java Collection Concatenate concat(Collection parts, int start, String defaultText)

Here you can find the source of concat(Collection parts, int start, String defaultText)

Description

concat

License

Open Source License

Declaration

public static String concat(Collection<String> parts, int start, String defaultText) 

Method Source Code

//package com.java2s;
/**/*from  w  ww .  j a va2 s .  com*/
 * This file is part of FoxBukkitChat.
 *
 * FoxBukkitChat is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * FoxBukkitChat is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with FoxBukkitChat.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Collection;

public class Main {
    public static String concat(Collection<String> parts, int start, String defaultText) {
        // TODO: optimize
        return concatArray(parts.toArray(new String[parts.size()]), start, defaultText);
    }

    public static String concatArray(String[] array, int start, String defaultText) {
        if (array.length <= start)
            return defaultText;

        if (array.length <= start + 1)
            return array[start]; // optimization

        StringBuilder ret = new StringBuilder(array[start]);
        for (int i = start + 1; i < array.length; i++) {
            ret.append(' ');
            ret.append(array[i]);
        }
        return ret.toString();
    }
}

Related

  1. concat(boolean removeDuplicates, Collection firstCollection, Collection... collections)
  2. concat(Collection> classes, String separator)
  3. concat(Collection collection, String delimiter)
  4. concat(Collection c)
  5. concat(Collection items)
  6. concat(Collection pieces, String delim)
  7. concat(Collection a, Collection b)
  8. concat(Collection a, int offset, String sep, String start, String end)
  9. concat(Collection first, Collection second)