StringUtils { public static String join(String[] array, String delimiter) { if (array == null) { return null; } if (delimiter == null) { delimiter = ""; } StringBuilder buf = new StringBuilder(); for (int i = 0; i < array.length; i++) { buf.append(array[i]); if (i < array.length - 1) { buf.append(delimiter); } } return buf.toString(); }  static int countWords(String str, boolean all); static String join(String[] array, String delimiter); static String quoteMetacharacters(String str); static String stripNasties(String str);  }
@Test public void testJoin() { assertThat(StringUtils.join(new String[] {"a"}, ","), is(equalTo("a"))); assertThat(StringUtils.join(new String[] {"a", "b"}, ","), is(equalTo("a,b"))); assertThat(StringUtils.join(new String[] {"a", "b", "c"}, ","), is(equalTo("a,b,c"))); assertThat(StringUtils.join(new String[] {"foo", "bar"}, ""), is(equalTo("foobar"))); assertThat(StringUtils.join(new String[] {}, ","), is(equalTo(""))); assertThat(StringUtils.join(new String[] {}, ""), is(equalTo(""))); assertThat(StringUtils.join(null, ","), is(equalTo(null))); }