Java Collection Join join(Collection strings, String sep)

Here you can find the source of join(Collection strings, String sep)

Description

join

License

Open Source License

Declaration

public static String join(Collection<String> strings, String sep) 

Method Source Code


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

import java.util.*;

public class Main {
    public static String join(Collection<String> strings, String sep) {
        if (strings.isEmpty()) {
            return "";
        }//from   w  ww.j  a va  2 s .co m

        StringBuilder sb = new StringBuilder();

        for (String parameterName : strings) {
            sb.append(parameterName).append(sep);
        }

        String names = sb.substring(0, sb.length() - sep.length());
        return names;
    }

    /**
     * isEmpty compatible with Java 5
     */
    public static boolean isEmpty(String s) {
        return s == null || s.length() == 0;
    }
}

Related

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