P15 { public static <T> List<T> duplicate(final List<T> list, final int times) { return list.stream().flatMap(e -> Collections.nCopies(times, e).stream()).collect(toList()); }  static List<T> duplicate(final List<T> list, final int times);  }
@Test public void shouldDuplicateElementsInAList() throws Exception { List<String> duplicates = P15.duplicate(Arrays.asList("a", "b", "c"), 3); assertThat(duplicates, hasSize(9)); assertThat(duplicates, contains("a", "a", "a", "b", "b", "b", "c", "c", "c")); }