Java Collection Join joinAndDelimit(final Collection strings, final String sep, final String delim)

Here you can find the source of joinAndDelimit(final Collection strings, final String sep, final String delim)

Description

join And Delimit

License

Open Source License

Declaration

public static String joinAndDelimit(final Collection<String> strings, final String sep, final String delim) 

Method Source Code

//package com.java2s;
/**//from  w  w w  .  j a  v  a 2  s .co m
 * ADOBE SYSTEMS INCORPORATED
 * Copyright 2009-2013 Adobe Systems Incorporated
 * All Rights Reserved.
 *
 * NOTICE: Adobe permits you to use, modify, and distribute
 * this file in accordance with the terms of the MIT license,
 * a copy of which can be found in the LICENSE.txt file or at
 * http://opensource.org/licenses/MIT.
 */

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

public class Main {
    /**
     *
     */
    public static String joinAndDelimit(final Collection<String> strings, final String sep, final String delim) {
        return joinAndDelimit(strings, sep, delim, delim);
    }

    /**
     *
     */
    public static String joinAndDelimit(final Collection<String> strings, final String sep, final String ldelim,
            final String rdelim) {
        final String joined = join(strings, sep);
        return joined.length() > 0 ? ldelim + joined + rdelim : "";
    }

    /**
     *
     */
    public static String join(final Iterable<String> strings, final String sep) {
        final StringBuilder b = new StringBuilder();
        final Iterator<String> iter = strings.iterator();

        if (iter.hasNext()) {
            b.append(iter.next());
            while (iter.hasNext())
                b.append(sep).append(iter.next());
        }

        return b.toString();
    }
}

Related

  1. join(String token, Collection strings)
  2. join(String[] collection, String delimiter)
  3. join(String[] collection, String separator)
  4. join(StringBuilder builder, Collection strs)
  5. join2(Collection list, String delimiter)
  6. joinAsString(Collection collection, String separator)
  7. joinAsStrings(Collection values, String separator)
  8. joinCol(Collection lst, String delim)
  9. joinCollection(Collection collection, char delimiter)