String.join()

  1. public static String join(CharSequence delimiter, CharSequence... elements) {
  2. Objects.requireNonNull(delimiter);
  3. Objects.requireNonNull(elements);
  4. // Number of elements not likely worth Arrays.stream overhead.
  5. StringJoiner joiner = new StringJoiner(delimiter);
  6. for (CharSequence cs: elements) {
  7. joiner.add(cs);
  8. }
  9. return joiner.toString();
  10. }