Java Iterable Join join(Iterable items, String delimiter)

Here you can find the source of join(Iterable items, String delimiter)

Description

join

License

Open Source License

Parameter

Parameter Description
items a parameter
delimiter a parameter

Return

delimiter separated string of items

Declaration

public static <T> String join(Iterable<T> items, String delimiter) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Iterator;

public class Main {
    /**// www .java 2 s  .c  om
     * @param items
     * @param delimiter
     * @return delimiter separated string of items
     */
    public static <T> String join(Iterable<T> items, String delimiter) {
        Iterator<T> i = items.iterator();
        if (!i.hasNext())
            return "";

        StringBuilder sb = new StringBuilder();
        sb.append(i.next());
        while (i.hasNext()) {
            sb.append(delimiter);
            sb.append(i.next());
        }

        return sb.toString();
    }
}

Related

  1. join(Iterable array, String joiner)
  2. join(Iterable coll, String sep)
  3. join(Iterable coll, String sep)
  4. join(Iterable coll, String sep)
  5. join(Iterable coll, String separator)
  6. join(Iterable iterable)
  7. join(Iterable parts, String delimiter)
  8. join(Iterable sequence, String delimiter)
  9. join(Iterable values, String separator)