Java String Join strjoinNL(String... args)

Here you can find the source of strjoinNL(String... args)

Description

strjoin with a newline as the separator

License

Open Source License

Declaration

public static String strjoinNL(String... args) 

Method Source Code

//package com.java2s;

import java.util.List;

public class Main {
    /** strjoin with a newline as the separator */
    public static String strjoinNL(String... args) {
        return join("\n", args);
    }/*from w  w  w.j a v a 2 s  .  c o m*/

    /** strjoin with a newline as the separator */
    public static String strjoinNL(List<String> args) {
        return join("\n", args);
    }

    private static String join(String sep, List<String> a) {
        return join(sep, a.toArray(new String[0]));
    }

    private static String join(String sep, String... a) {
        if (a.length == 0)
            return "";

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

        StringBuffer sbuff = new StringBuffer();
        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();
    }
}

Related

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