Java Collection Join joinEmptyItemIncluded(Collection stringCollection, String delimiter)

Here you can find the source of joinEmptyItemIncluded(Collection stringCollection, String delimiter)

Description

join Empty Item Included

License

BSD License

Declaration

public static String joinEmptyItemIncluded(Collection<String> stringCollection, String delimiter) 

Method Source Code

//package com.java2s;
/*L/* w  ww .j a v  a 2  s  .  co  m*/
 *  Copyright SAIC
 *  Copyright SAIC-Frederick
 *
 *  Distributed under the OSI-approved BSD 3-Clause License.
 *  See http://ncip.github.com/cananolab/LICENSE.txt for details.
 */

import java.util.Collection;
import java.util.Iterator;

public class Main {
    public static String joinEmptyItemIncluded(Collection<String> stringCollection, String delimiter) {
        StringBuffer buffer = new StringBuffer();
        if (stringCollection == null || stringCollection.isEmpty()) {
            return "";
        }

        Iterator iter = stringCollection.iterator();
        while (iter.hasNext()) {
            String item = (String) iter.next();
            if (item == null)
                item = "";
            buffer.append(item);
            if (iter.hasNext()) {
                buffer.append(delimiter);
            }
        }
        return buffer.toString();
    }

    /**
     * Return true for Null or empty string, false otherwise.
     */
    public static boolean isEmpty(String str) {
        return (str == null || str.trim().length() == 0);
    }
}

Related

  1. joinCollection(Collection collection, char delimiter)
  2. joinCollection(Collection a)
  3. joinCollections(final Collection target, final Collection... collections)
  4. joinCollectionToString(Collection list, String str)
  5. joinCommaDelimitedList(Collection list)
  6. joinList(@SuppressWarnings("rawtypes") Collection c)
  7. joinNullSafe(Collection collection, String separator)
  8. joinObjects(Collection objects)
  9. joinQuoted(Collection col)

  10. HOME | Copyright © www.java2s.com 2016