StringUtils { @Nonnull public static String mkString(@Nonnull final String separator, @Nonnull final Collection<?> values) { assert values != null; assert separator != null; boolean first = true; final StringBuilder sb = new StringBuilder(); for (final Object value : values) { if (value != null) { final String str = value.toString(); if (!str.isEmpty()) { if (!first) { sb.append(separator); } else { first = false; } sb.append(str); } } } return sb.toString(); } private  StringUtils(); @Nonnull static String nullToEmpty(@Nullable final String s); @Nullable static String emptyToNull(@Nullable final String s); @Nullable static String trim(@Nullable final String s); @Nullable static List<String> trim(@Nullable final List<String> sList); @Nullable static Set<String> trim(@Nullable final Set<String> sSet); @Nullable static String literalToLowerCase(@Nullable final String s); @Nonnull static int[] toCodePoints(@Nonnull final String s); @Nonnull static String mkString(@Nonnull final String separator, @Nonnull final Collection<?> values); @Nonnull static String mkRevString(@Nonnull final String separator, @Nonnull final Collection<T> values); @SafeVarargs @Nonnull static String mkString(@Nonnull final String separator, @Nonnull final T... values); @SafeVarargs @Nonnull static String mkRevString(@Nonnull final String separator, @Nonnull final T... values); @Nonnull static String generateRandomStringFromChars(@Nonnull final char[] chars, final int length); @SuppressWarnings("ConstantConditions") @Nonnull static String encodeToJsonString(@Nonnull final String input); @Nullable static String decodeFromJsonString(@Nonnull final String input);  }
@Test public void testMkStringList() { LOG.info("testMkStringList"); final Collection<Integer> list = new ArrayList<>(); list.add(1); list.add(2); list.add(3); final String result = StringUtils.mkString("|", list); Assert.assertEquals("1|2|3", result); }
@Test public void testMkStringArray() { LOG.info("testMkStringArray"); final String result = StringUtils.mkString(", ", "joe", "bob", "alice"); Assert.assertEquals("joe, bob, alice", result); }
@Test public void testMkStringArrayEmpty() { LOG.info("testMkStringArrayEmpty"); String result = StringUtils.mkString(", ", "", "2", "3"); Assert.assertEquals("2, 3", result); result = StringUtils.mkString(", ", "1", "", "3"); Assert.assertEquals("1, 3", result); result = StringUtils.mkString(", ", "1", "2", ""); Assert.assertEquals("1, 2", result); result = StringUtils.mkString(", ", null, "2", "3"); Assert.assertEquals("2, 3", result); result = StringUtils.mkString(", ", "1", null, "3"); Assert.assertEquals("1, 3", result); result = StringUtils.mkString(", ", "1", "2", null); Assert.assertEquals("1, 2", result); }