P17 { public static <T> Map<Boolean, List<T>> split(List<T> list, int n) { return IntStream .range(0, list.size()) .mapToObj(i -> new SimpleEntry<>(i, list.get(i))) .collect(partitioningBy(entry -> entry.getKey() < n, mapping(SimpleEntry::getValue, toList()))); }  static Map<Boolean, List<T>> split(List<T> list, int n);  }
@Test public void shouldSplitInTwoHalves() throws Exception { Map<Boolean, List<String>> result = P17.split(Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "k"), 3); assertThat(result.get(true), contains("a", "b", "c")); assertThat(result.get(false), contains("d", "e", "f", "g", "h", "i", "k")); }