Java String Join strjoin(String sep, String... args)

Here you can find the source of strjoin(String sep, String... args)

Description

Concatentate string, using a separator

License

Open Source License

Declaration

public static String strjoin(String sep, String... args) 

Method Source Code

//package com.java2s;

import java.util.List;

public class Main {
    /** Concatentate string, using a separator */
    public static String strjoin(String sep, String... args) {
        return join(sep, args);
    }// www . ja va2s  . co  m

    /** Concatentate string, using a separator */
    public static String strjoin(String sep, List<String> args) {
        return join(sep, args);
    }

    /** Join an array of strings */
    private static String join(String sep, String... a) {
        if (a.length == 0)
            return "";

        if (a.length == 1)
            return a[0];

        StringBuilder sbuff = new StringBuilder();
        sbuff.append(a[0]);

        for (int i = 1; i < a.length; i++) {
            if (sep != null)
                sbuff.append(sep);
            sbuff.append(a[i]);
        }
        return sbuff.toString();
    }

    /** Join a list of strings */
    private static String join(String sep, List<String> a) {
        return join(sep, a.toArray(new String[0]));
    }
}

Related

  1. joinValues(Map map, String separator)
  2. joinWithSeparation(String a, String separator, String b)
  3. merge(ArrayList pArrayList, String pJoin)
  4. mergeDependencies(Set bundleDeps, List deps, Map disjointSets)
  5. prefixed_join(String padder, Vector v, boolean quoted)
  6. strjoinNL(String... args)