Challenge: Build a Custom Collector for Category Counting
Завдання
Swipe to start coding
You need to implement a custom Collector
that processes a list of products and counts how many products belong to each category.
- In the
supplier()
method, return a newHashMap
. - In the
accumulator()
method, call theget()
method on theproduct
map to retrieve the value of the"category"
key and pass it as the first parameter of themerge()
method. - For the second parameter in the same method, provide the initial value (
1
). - In the
combiner()
method, pass thekey
ofmap2
as the first parameter of themerge()
method. - For the second parameter in the same method, pass the
value
of themap2
. - In the
finisher()
method, return themap
without modifying it using a lambda. - In the
characteristics()
method, return a set that ensures the collection remains unchanged (IDENTITY_FINISH
). - In the
collect()
method, pass the implementation of theCollector
interface (CategoryCountCollector
).
Рішення
solution.java
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 3. Розділ 2
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Awesome!
Completion rate improved to 2.33
Challenge: Build a Custom Collector for Category Counting
Свайпніть щоб показати меню
Завдання
Swipe to start coding
You need to implement a custom Collector
that processes a list of products and counts how many products belong to each category.
- In the
supplier()
method, return a newHashMap
. - In the
accumulator()
method, call theget()
method on theproduct
map to retrieve the value of the"category"
key and pass it as the first parameter of themerge()
method. - For the second parameter in the same method, provide the initial value (
1
). - In the
combiner()
method, pass thekey
ofmap2
as the first parameter of themerge()
method. - For the second parameter in the same method, pass the
value
of themap2
. - In the
finisher()
method, return themap
without modifying it using a lambda. - In the
characteristics()
method, return a set that ensures the collection remains unchanged (IDENTITY_FINISH
). - In the
collect()
method, pass the implementation of theCollector
interface (CategoryCountCollector
).
Рішення
solution.java
Все було зрозуміло?
Дякуємо за ваш відгук!
Awesome!
Completion rate improved to 2.33Секція 3. Розділ 2
single