Java Array Join joinWithSpaces(final String[] cmds)

Here you can find the source of joinWithSpaces(final String[] cmds)

Description

join With Spaces

License

Common Public License

Declaration

public static String joinWithSpaces(final String[] cmds) 

Method Source Code

//package com.java2s;
/*/*w w w .  j a v a 2  s .com*/
 * @author Fabio Zadrozny
 * Created: June 2005
 * License: Common Public License v1.0
 */

import java.util.List;

public class Main {
    public static String joinWithSpaces(final String[] cmds) {
        return join(" ", cmds);
    }

    /**
     * Same as Python join: Go through all the paths in the string and join them
     * with the passed delimiter.
     */
    public static String join(final String delimiter, final String[] splitted) {
        final StringBuilder buf = new StringBuilder(splitted.length * 100);
        for (final String string : splitted) {
            if (buf.length() > 0) {
                buf.append(delimiter);
            }
            buf.append(string);
        }
        return buf.toString();
    }

    /**
     * Same as Python join: Go through all the paths in the string and join them
     * with the passed delimiter.
     */
    public static String join(final String delimiter, final List<String> splitted) {
        final StringBuilder buf = new StringBuilder(splitted.size() * 100);
        for (final String string : splitted) {
            if (buf.length() > 0) {
                buf.append(delimiter);
            }
            buf.append(string);
        }
        return buf.toString();
    }
}

Related

  1. joinString(String[] str, String delimiter)
  2. joinStringArray(String[] array1, String[] array2)
  3. joinStrings(String[] strings, String separator)
  4. joinTokens(String tokens[], String pad)
  5. joinWithPrefixes(String[] prefixes, String name, String sep)
  6. stringJoin(Object[] array, String separator)