CollectionUtil { public static <T> String smartJoin(final Collection<T> collection, final Generator<T, String> stringGenerator, final String joiner) { if (collection.isEmpty()) { return ""; } final StringBuilder stringBuilder = new StringBuilder(); final Iterator<T> iterator = collection.iterator(); while (iterator.hasNext()) { stringBuilder.append(stringGenerator.generate(iterator.next())); if (iterator.hasNext()) { stringBuilder.append(joiner); } } return stringBuilder.toString(); }  static int clear(final Collection collection); static List<String> toStringList(final Collection<T> collection); static String smartJoin(final Collection<T> collection,
        final Generator<T, String> stringGenerator, final String joiner); @SafeVarargs static C arrayToCollection(
        final Supplier<C> creator, final T... array); @Deprecated static Collection<String> toStringCollection(final String stringList); static String join(final Collection<T> collection, String joiner); static boolean containsIgnoreCase(final Collection<? extends String> collection,
        final String string);  }
@Test void smartJoin() { final Collection<Integer> collection = Arrays.asList(3, 8, 6); String joined = CollectionUtil.smartJoin(collection, i -> "{" + i + "}", ", "); Assertions.assertEquals("{3}, {8}, {6}", joined); }