Challenge: Selecting Random Products Within a Category
Tarefa
Swipe to start coding
Imagine you have a list of products from an online store. Your goal is to group them by category, pick a random product from each group, and display the result.
- Group the list of products by
categoryusinggroupingBy(). - For each category (
productList), get the list of products using thestream()method and select a random product withfindAny(). - Check if the
Optionalcontains a value usingifPresent(). - If
Optionalhas a value, print the information in the following format:"Category: {category} => {product}".
Solução
solution.java
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 3. Capítulo 11
single
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Suggested prompts:
Resumir este capítulo
Explicar o código em file
Explicar por que file não resolve a tarefa
Awesome!
Completion rate improved to 2.33
Challenge: Selecting Random Products Within a Category
Deslize para mostrar o menu
Tarefa
Swipe to start coding
Imagine you have a list of products from an online store. Your goal is to group them by category, pick a random product from each group, and display the result.
- Group the list of products by
categoryusinggroupingBy(). - For each category (
productList), get the list of products using thestream()method and select a random product withfindAny(). - Check if the
Optionalcontains a value usingifPresent(). - If
Optionalhas a value, print the information in the following format:"Category: {category} => {product}".
Solução
solution.java
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 3. Capítulo 11
single