### Question:
StreamUtils { static <K, V> Collector<Entry<K, V>, ?, Map<K, V>> toLinkedHashMap() { return Collectors.toMap(Entry::getKey, Entry::getValue, throwingMerger(), LinkedHashMap::new); } private  StreamUtils();   }### Answer:
@Test void testToLinkedHashMap() throws Exception { Map<String, String> result = Stream.of("a", "b", "c") .map(value -> new SimpleEntry<>(value, value)) .collect(StreamUtils.toLinkedHashMap()); assertThat(result) .containsExactly( entry("a", "a"), entry("b", "b"), entry("c", "c") ); }
@Test void testToLinkedHashMap_duplicates() throws Exception { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> Stream.of("a", "b", "c", "b") .map(value -> new SimpleEntry<>(value, value)) .collect(StreamUtils.toLinkedHashMap())) .withMessage("Duplicate key 'b'"); }