Java Iterable Join join(Iterable s, String delimiter)

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

Description

Joins array of strings to string

License

Open Source License

Parameter

Parameter Description
s a parameter
delimiter a parameter

Declaration

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

Method Source Code


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

import java.util.*;

public class Main {
    /**//  w  w w . ja  v  a  2  s . co m
     * Joins array of strings to string
     *
     * @param s
     * @param delimiter
     * @return
     */
    public static String join(Iterable<String> s, String delimiter) {
        if (s == null)
            return "";
        Iterator<String> iter = s.iterator();
        StringBuilder builder = new StringBuilder(iter.next());
        while (iter.hasNext()) {
            builder.append(delimiter).append(iter.next());
        }
        return builder.toString();
    }
}

Related

  1. join(Iterable iterable, String separator)
  2. join(Iterable array)
  3. join(Iterable items, String separator)
  4. join(Iterable iterable, String delimiter)
  5. join(Iterable s, String delimiter)
  6. join(Iterable s, String delimiter)
  7. join(Iterable source, char delimiter)
  8. join(Iterable source, String separator)
  9. join(Iterable strings)