Java Collection Join join(Collection strings, String delimiter)

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

Description

join

License

Open Source License

Declaration

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

Method Source Code


//package com.java2s;

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

public class Main {
    public static String join(Collection<String> strings, String delimiter) {
        if (strings == null) {
            throw new IllegalArgumentException("strings is null");
        }//from   www.j ava  2s . com

        if (delimiter == null) {
            throw new IllegalArgumentException("delimiter is null");
        }

        StringBuilder builder = new StringBuilder();

        for (Iterator<String> iterator = strings.iterator(); iterator.hasNext();) {
            builder.append(iterator.next());
            builder.append(delimiter);
        }

        if (builder.length() > 0) {
            return builder.substring(0, builder.length() - delimiter.length());
        } else {
            return "";
        }
    }
}

Related

  1. join(Collection s, String delimiter)
  2. join(Collection src, String delim)
  3. join(Collection strings)
  4. join(Collection strings, String delimiter)
  5. join(Collection strings, String delimiter)
  6. join(Collection strings, String delimiter)
  7. join(Collection strings, String delimiter)
  8. join(Collection strings, String sep)
  9. join(Collection strings, String sep)