Java Iterable Join join(Iterable c, String delimeter)

Here you can find the source of join(Iterable c, String delimeter)

Description

join

License

Open Source License

Declaration

public static String join(Iterable<?> c, String delimeter) 

Method Source Code

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

import java.util.Iterator;

public class Main {
    public static String join(Iterable<?> c, String delimeter) {
        StringBuilder sb = new StringBuilder();
        Iterator<?> it = c.iterator();
        while (it.hasNext()) {
            sb.append(it.next());//from w ww. j av a2s .c om
            if (!it.hasNext())
                break;
            sb.append(delimeter);
        }
        return sb.toString();
    }

    public static <T> String join(T[] c, String delimeter) {
        StringBuilder sb = new StringBuilder();
        boolean first = true;
        for (T t : c) {
            if (first)
                first = false;
            else
                sb.append(delimeter);
            sb.append(t);
        }
        return sb.toString();
    }
}

Related

  1. join(Iterable elements, String delimiter)
  2. join(Iterable iterable, String delimiter)
  3. join(Iterable s, String delimiter)
  4. join(Iterable iterable, String delimiter)
  5. join(Iterable joinee, String joiner)
  6. join(Iterable elements, String separator)
  7. join(Iterable elements, String separator)
  8. join(Iterable elements, String separator)
  9. join(Iterable items)