Java Iterable Join join(Iterable coll, String sep)

Here you can find the source of join(Iterable coll, String sep)

Description

join

License

Open Source License

Declaration

public static <T> String join(Iterable<T> coll, String sep) 

Method Source Code

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

import java.util.Iterator;

public class Main {
    public static <T> String join(T[] arr, String sep) {
        String ret = "";
        for (int i = 0; i < arr.length; i++) {
            ret = ret + arr[i];//from  w  ww. j  av  a 2s.c o m
            if (i < arr.length - 1) {
                ret = ret + sep;
            }
        }
        return ret;
    }

    public static <T> String join(Iterable<T> coll, String sep) {
        Iterator<T> it = coll.iterator();
        String ret = "";
        while (it.hasNext()) {
            ret = ret + it.next();
            if (it.hasNext()) {
                ret = ret + sep;
            }
        }
        return ret;
    }
}

Related

  1. join(Iterable source, String separator)
  2. join(Iterable strings)
  3. join(Iterable strings, String delimiter)
  4. join(Iterable strings, String separator)
  5. join(Iterable array, String joiner)
  6. join(Iterable coll, String sep)
  7. join(Iterable coll, String sep)
  8. join(Iterable coll, String separator)
  9. join(Iterable items, String delimiter)