Java Collection Join join(final String s, final Collection c)

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

Description

join

License

LGPL

Declaration

static String join(final String s, final Collection<?> c) 

Method Source Code

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

import java.util.Collection;

public class Main {
    static String join(final String s, final Collection<?> c) {
        final StringBuilder sb = new StringBuilder();
        for (final Object o : c) {
            sb.append(o);/*from  w  w  w.  jav a  2  s . c  o  m*/
            sb.append(s);
        }
        if (c != null && c.size() > 0) {
            sb.delete(sb.length() - s.length(), sb.length());
        }
        return sb.toString();
    }

    static <T extends Object> String join(final String s, final T... c) {
        if (c == null || c.length == 0)
            return "";
        final StringBuilder sb = new StringBuilder();
        for (final Object o : c) {
            sb.append(o == null ? "" : o.toString());
            sb.append(s);
        }
        return sb.delete(sb.length() - s.length(), sb.length()).toString();
    }
}

Related

  1. join(final Collection collection, final String delimiter)
  2. join(final Collection objs, final String delimiter)
  3. join(final Collection objs, String delimiter)
  4. join(final String d, final Collection c)
  5. join(final String delimiter, final Collection elements)
  6. join(final String sep, final Collection c)
  7. join(final String sep, final Collection strs)
  8. join(final String separator, final Collection objects)
  9. join(final String separator, final Collection objects)