StringUtilities { public static String implode(String[] array, String sepString) { if (array==null) return null; StringBuilder ret = new StringBuilder(); if (sepString==null) sepString=""; for (int i = 0 ; i<array.length ; i++) { ret.append(array[i]); if (!(i==array.length-1)) ret.append(sepString); } return ret.toString(); }  static String escape(String source); static String escape(String source, char delimiter); static String unescape(String source); static String implode(String[] array, String sepString); static String implodeMultiline(List<String> lines); static String truncateSequencesIfNecessary(String text, int maxConsecutiveLength); static String stripSuffix(String string, String suffix); static String quote(Object object); static Set<String> split(String s);  }
@Test public void testImplode() { assertEquals(StringUtilities.implode(null, null), null); assertEquals(StringUtilities.implode(new String[0], null), ""); assertEquals(StringUtilities.implode(new String[] {"foo"}, null), "foo"); assertEquals(StringUtilities.implode(new String[] {"foo"}, "asdfsdfsadfsadfasdfs"), "foo"); assertEquals(StringUtilities.implode(new String[] {"foo", "bar"}, null), "foobar"); assertEquals(StringUtilities.implode(new String[] {"foo", "bar"}, "\n"), "foo\nbar"); assertEquals(StringUtilities.implode(new String[] {"foo"}, "\n"), "foo"); assertEquals(StringUtilities.implode(new String[] {"foo", "bar", null}, "\n"), "foo\nbar\nnull"); assertEquals(StringUtilities.implode(new String[] {"foo", "bar"}, "\n"), "foo\nbar"); assertEquals(StringUtilities.implode(new String[] {"foo", "bar", "baz"}, null), "foobarbaz"); }