Java Iterable Join join(String delimiter, Iterable stringsIterable)

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

Description

join

License

Apache License

Declaration

public static String join(String delimiter, Iterable<String> stringsIterable) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class Main {
    public static String join(String delimiter, Iterable<String> stringsIterable) {
        List<String> strings = new LinkedList<>();
        Iterator<String> iterator = stringsIterable.iterator();
        while (iterator.hasNext()) {
            strings.add(iterator.next());
        }/*from   w w w. ja va  2s  .  c  om*/

        StringBuilder ab = new StringBuilder();
        for (int i = 0; i < strings.size(); i++) {
            ab.append(strings.get(i));
            if (i != strings.size() - 1) {
                ab.append(delimiter);
            }
        }
        return ab.toString();
    }
}

Related

  1. join(Iterable sequence, String delimiter)
  2. join(Iterable values, String separator)
  3. join(Iterable values, String separator)
  4. join(Iterator iterator, String separator)
  5. join(String delimiter, Iterable strings)
  6. join(String delimiter, String wrap, Iterable objs)
  7. join(String glue, Iterable pieces)
  8. join(String glue, Iterable tokens)
  9. join(String sep, Iterable strings)