Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumJavaCollectors toMap groupingBySingle-choice MCQ

A stream of strings is collected with Collectors.toMap using the first character as the key. What happens when two strings share the same first character?

List.of("apple", "avocado", "banana").stream() .collect(Collectors.toMap(s -> s.charAt(0), s -> s));