code: public static String join(Collection collection,
                                String separator,
                                boolean trailing) {
          StringBuilder b = new StringBuilder();
          // fast return on empty collection
          if (collection.isEmpty()) {
              return trailing ? separator : "";
          }
          for (Object o : collection) {
              b.append(o);
              b.append(separator);
          }
          int length = separator.length();
          String s = b.toString();
          return (trailing || s.isEmpty()) ?
                  s : (b.substring(0, b.length() - length));
      }
docs: Join an collection of objects with a separator that appears after every
  instance in the list -optionally at the end
  
  @param collection collection to call toString() on each element
  @param separator  separator string
  @param trailing   add a trailing entry or not
  @return the joined entries