P14 { public static <T> List<T> duplicate(List<T> list) { return list.stream().flatMap(e -> Stream.of(e, e)).collect(toList()); }  static List<T> duplicate(List<T> list);  }
@Test public void shouldDuplicateElementsInAList() throws Exception { List<String> duplicates = P14.duplicate(Arrays.asList("a", "b", "c", "d")); assertThat(duplicates, hasSize(8)); assertThat(duplicates, contains("a", "a", "b", "b", "c", "c", "d", "d")); }