Java Collection Join join(Collection s, String delimiter)

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

Description

Given a collection of stuff, joins their string representation into one string using delimiter

License

Open Source License

Parameter

Parameter Description
s a parameter
delimiter a parameter

Declaration

public static String join(Collection<?> s, String delimiter) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {
    /**//  w  w  w .j  a v  a  2  s.c om
     * Given a collection of stuff, joins their string representation into one
     * string using delimiter
     *
     * @param s
     * @param delimiter
     * @return
     */
    public static String join(Collection<?> s, String delimiter) {
        StringBuilder builder = new StringBuilder();
        Iterator<?> iter = s.iterator();
        while (iter.hasNext()) {
            builder.append(iter.next());
            if (!iter.hasNext()) {
                break;
            }
            builder.append(delimiter);
        }
        return builder.toString();
    }
}

Related

  1. join(Collection objs, String delimiter)
  2. join(Collection objs, String sep)
  3. join(Collection s)
  4. join(Collection s, String delimiter)
  5. join(Collection s, String delimiter)
  6. join(Collection strings, String delimiter)
  7. join(Collection strings, String delimiter)
  8. join(Collection strings, String separator)
  9. join(Collection strings, String separator)