Java Collection Join join(StringBuilder builder, Collection strs)

Here you can find the source of join(StringBuilder builder, Collection strs)

Description

join

License

Apache License

Declaration

public static StringBuilder join(StringBuilder builder, Collection<String> strs) 

Method Source Code


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

import java.util.Collection;

import java.util.List;

public class Main {
    public static String join(List<String> strs) {
        return join(new StringBuilder(), strs).toString();
    }/*from   w w w.  j  ava2  s  . c om*/

    public static String join(String[] strs) {
        return join(new StringBuilder(), strs).toString();
    }

    public static StringBuilder join(StringBuilder builder, Collection<String> strs) {
        int i = 0;
        for (String s : strs) {
            if (i != 0)
                builder.append(',');
            builder.append(s);
            i++;
        }
        return builder;
    }

    public static StringBuilder join(StringBuilder builder, String[] strs) {
        for (int i = 0; i < strs.length; i++) {
            if (i != 0)
                builder.append(",");
            builder.append(strs[i]);
        }
        return builder;
    }
}

Related

  1. join(String separator, Collection objects)
  2. join(String separator, Collection values)
  3. join(String token, Collection strings)
  4. join(String[] collection, String delimiter)
  5. join(String[] collection, String separator)
  6. join2(Collection list, String delimiter)
  7. joinAndDelimit(final Collection strings, final String sep, final String delim)
  8. joinAsString(Collection collection, String separator)
  9. joinAsStrings(Collection values, String separator)