Java Collection Join join(Collection coll, String delimiter)

Here you can find the source of join(Collection coll, String delimiter)

Description

Returns the comma seprated string example:-a@b.com,c@d.com,d@e.com

License

Apache License

Parameter

Parameter Description
coll a parameter
delimiter a parameter

Return

String

Declaration

public static String join(Collection<String> coll, String delimiter) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Collection;

public class Main {
    /****//from  w w w.ja va 2s .com
     * Returns the comma seprated string example:-a@b.com,c@d.com,d@e.com
     * 
     * @param coll
     * @param delimiter
     * @return String
     */
    public static String join(Collection<String> coll, String delimiter) {
        if (coll.isEmpty())
            return "";

        StringBuilder sb = new StringBuilder();

        for (String x : coll)
            sb.append(x + delimiter);

        sb.delete(sb.length() - delimiter.length(), sb.length());

        return sb.toString();
    }

    /**
     * Method is useful for checking the given string is empty or not if it is
     * empty then return true otherwise return false.
     * 
     * @param tmp
     * @return boolean
     */

    public static boolean isEmpty(String str) {
        if (str == null)
            return true;
        if (str.trim().length() == 0) {
            return true;
        }
        return false;
    }
}

Related

  1. join(Collection data)
  2. join(Collection c, String separator)
  3. join(Collection args, String delimeter)
  4. join(Collection c)
  5. join(Collection c, String joinSymbol)
  6. join(Collection coll, String delimiter)
  7. join(Collection collection)
  8. join(Collection collection)
  9. join(Collection collection, String separator)