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

Contenido del 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

Tarea

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).

Solución

java

solution

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 2
toggle bottom row

book
Challenge: Build a Custom Collector for Category Counting

Tarea

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).

Solución

java

solution

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 2
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt