Strings { public static String join(String separator, Iterator<?> parts) { Preconditions.checkNotNull(separator, "separator"); Preconditions.checkNotNull(parts, "parts"); StringBuilder builder = new StringBuilder(); if (parts.hasNext()) { builder.append(parts.next().toString()); while (parts.hasNext()) { builder.append(separator); builder.append(parts.next().toString()); } } return builder.toString(); } private  Strings(); static boolean isNullOrEmpty(String string); static String join(String separator, Iterator<?> parts);  }
@Test public void testJoin() throws Exception { assertEquals(Strings.join(", ", emptyIterator()), ""); assertEquals(Strings.join(", ", Collections.singletonList(1).iterator()), "1"); assertEquals(Strings.join(", ", Arrays.asList(1, 2).iterator()), "1, 2"); }