Java Iterable Join join(final Iterable objs, final String delimiter)

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

Description

join

License

Open Source License

Declaration

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

Method Source Code


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

import java.util.Iterator;

public class Main {
    public static <T> String join(final Iterable<T> objs, final String delimiter) {
        Iterator<T> iter = objs.iterator();
        if (!iter.hasNext()) {
            return "";
        }//ww  w  .  j a v  a 2 s .  c  om
        StringBuffer buffer = new StringBuffer(String.valueOf(iter.next()));
        while (iter.hasNext()) {
            buffer.append(delimiter).append(String.valueOf(iter.next()));
        }
        return buffer.toString();
    }
}

Related

  1. join(final Iterable items, final String separator)
  2. join(final Iterable iterable, final String separator)
  3. join(final Iterable container)
  4. join(final Iterable iterable, final String joinString)
  5. join(final Iterable objs, final String delimiter)
  6. join(final Iterable source)
  7. join(final Iterable... iterables)
  8. join(final String delimiter, final Iterable objs)
  9. join(Iterable elements, String delimiter)