CustomCollectors { public static <T, K, U> Collector<T, ?, Map<K,U>> toLinkedMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) { return Collectors.toMap(keyMapper, valueMapper, throwingMerger(), LinkedHashMap::new); } private  CustomCollectors(); static Collector<T, ?, Map<K,U>> toLinkedMap(Function<? super T, ? extends K> keyMapper,
                                          Function<? super T, ? extends U> valueMapper); static Collector<T, ?, M> toCustomMap(Function<? super T, ? extends K> keyMapper,
                                   Function<? super T, ? extends U> valueMapper,
                                   Supplier<M> mapSupplier);  }
@Test public void linked_map_collector_returns_map_with_insertion_order() { List<String> stringList = numberList(); Map<String, String> orderedMap = stringList.stream().collect(toLinkedMap(identity(), identity())); int i = 0; for (String val : orderedMap.keySet()) { assertEquals(stringList.get(i), val); i++; } }