Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Build a Custom Collector for Category Counting | Terminal Operations in the Stream API
Stream API
course content

Conteúdo do Curso

Stream API

Stream API

1. Fundamentals and Functional Capabilities of Stream API
4. Practical Applications of Stream API

book
Challenge: Build a Custom Collector for Category Counting

Tarefa

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.

  1. In the supplier() method, return a new HashMap.
  2. In the accumulator() method, call the get() method on the product map to retrieve the value of the "category" key and pass it as the first parameter of the merge() method.
  3. For the second parameter in the same method, provide the initial value (1).
  4. In the combiner() method, pass the key of map2 as the first parameter of the merge() method.
  5. For the second parameter in the same method, pass the value of the map2.
  6. In the finisher() method, return the map without modifying it using a lambda.
  7. In the characteristics() method, return a set that ensures the collection remains unchanged (IDENTITY_FINISH).
  8. In the collect() method, pass the implementation of the Collector interface (CategoryCountCollector).

Solução

java

solution

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 2
toggle bottom row

book
Challenge: Build a Custom Collector for Category Counting

Tarefa

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.

  1. In the supplier() method, return a new HashMap.
  2. In the accumulator() method, call the get() method on the product map to retrieve the value of the "category" key and pass it as the first parameter of the merge() method.
  3. For the second parameter in the same method, provide the initial value (1).
  4. In the combiner() method, pass the key of map2 as the first parameter of the merge() method.
  5. For the second parameter in the same method, pass the value of the map2.
  6. In the finisher() method, return the map without modifying it using a lambda.
  7. In the characteristics() method, return a set that ensures the collection remains unchanged (IDENTITY_FINISH).
  8. In the collect() method, pass the implementation of the Collector interface (CategoryCountCollector).

Solução

java

solution

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 2
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt