Java Iterable Join joinWith(Iterable elements, String join)

Here you can find the source of joinWith(Iterable elements, String join)

Description

join With

License

Open Source License

Declaration

public static String joinWith(Iterable<String> elements, String join) 

Method Source Code

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

import java.util.Iterator;

public class Main {
    public static String joinWith(Iterable<String> elements, String join) {
        StringBuilder result = new StringBuilder();

        Iterator<String> it = elements.iterator();

        if (it.hasNext()) {
            result.append(it.next());//from  w  w  w . ja  v a  2  s .  c  o  m
        }

        while (it.hasNext()) {
            result.append(join).append(it.next());
        }

        return result.toString();
    }
}

Related

  1. joinIterableOnComma(Iterable iterable)
  2. joinIterables(final Iterable... iterables)
  3. joinStr(CharSequence glue, Iterable parts)
  4. joinStrings(Iterable arr, String glue)
  5. joinStrings(Iterable strs, String sep)