comma Delimit - Java java.lang

Java examples for java.lang:String Split

Description

comma Delimit

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String strs = "java2s.com";
        System.out.println(commaDelimit(strs,"asdf"));
    }//  www. jav  a 2  s. com

    public static String commaDelimit(String... strs) {
        return join(true, ", ", strs);
    }

    public static String join(boolean discardBlanks, String delimiter,
            String... strs) {
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < strs.length; i++) {
            if (strs[i].isEmpty() && discardBlanks)
                continue;
            sb.append(strs[i]);
            if (i < strs.length - 1)
                sb.append(delimiter);
        }

        return sb.toString();
    }
}

Related Tutorials