First Non-Repeated Character
First Non-Repeated Character
The code provided indeed finds the first non-repeated character from the given string "Java Is
Awesome" using Java 8 Stream functions. Let's break down the code:
3. .collect(Collectors.groupingBy(Function.identity(), LinkedHashMap::new,
Collectors.counting())) groups the characters by their count using a LinkedHashMap to
maintain insertion order.
4. .entrySet().stream() converts the entry set of the map into a stream of entries.
5. .filter(entry -> entry.getValue() == 1) filters out the entries with count equal to 1.
6. .map(entry -> entry.getKey()) extracts the characters from the filtered entries.
7. .findFirst().get() gets the first character from the stream, which is the first non-repeated
character.
So yes, the provided code correctly finds the first non-repeated character from the given string.